Simulater/Generated switch statement range in c(c中的模拟器/生成的switch语句范围)
问题描述
在 c(99?) 或目标 C switch 语句中是否有支持范围大小写的技巧?我知道不支持这样写:
Is there a hack to support range case in a c(99?) or objective C switch statement ? I know this is not supported to write something like this:
switch(x)
case 1:
case 2..10:
case 11:
但我在想应该有一种方法可以使用#define 宏生成代码.当然我可以用案例列表定义一个宏,但我希望有一种更优雅的方式,比如CASERANGE(x,x+10) 会生成:
But I was thinking there should be a way to generate code with a #define macro. Of course I can define a macro with the list of cases but I was hoping for a more elegant way like CASERANGE(x,x+10) which would generate:
case x
case x+1
case x+2
有可能吗?
推荐答案
GCC 有一个 对 C 语言的扩展 允许与您的第一个示例类似的内容,但除此之外,如果有可移植/ANSI 的方式来实现它,那么现在就已经完成了.我不相信有一个.
GCC has an extension to the C language that allows something similar to your first example, but other than that, if there was a portable/ANSI way of doing it, it would have been done by now. I don't believe there is one.
这篇关于c中的模拟器/生成的switch语句范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:c中的模拟器/生成的switch语句范围


基础教程推荐
- Android文本颜色不会改变颜色 2022-01-01
- LocationClient 与 LocationManager 2022-01-01
- “让"到底是怎么回事?关键字在 Swift 中的作用? 2022-01-01
- 在 iOS 上默认是 char 签名还是 unsigned? 2022-01-01
- 如何使用 YouTube API V3? 2022-01-01
- :hover 状态不会在 iOS 上结束 2022-01-01
- 如何使 UINavigationBar 背景透明? 2022-01-01
- Android ViewPager:在 ViewPager 中更新屏幕外但缓存的片段 2022-01-01
- 使用 Ryzen 处理器同时运行 WSL2 和 Android Studio 2022-01-01
- 固定小数的Android Money Input 2022-01-01