c中的模拟器/生成的switch语句范围

Simulater/Generated switch statement range in c(c中的模拟器/生成的switch语句范围)
本文介绍了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语句范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)