作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
是否有任何带有扩展的 C 编译器能够在每个 case 语句末尾自动中断(类似于 Swift 提供的功能)或在未来的 C 规范中提供备用开关?
对此最感兴趣,以避免在广泛的 switch-case 场景中出现困惑。
我发现这工作“不错”,但更喜欢更清晰的行为。
#define case break; { } case
#define switch_break switch
switch_break (action)
{
default: printf ("Unknown action");
case action_none : // Nothing
case action_copy : doCopy ();
case action_paste : doPaste ();
case action_none : break; /* C requires a statement after final case */
}
最佳答案
如果您讨厌每次都编写 break
,请将 switch
语句包装在函数内。然后可以将 break
替换为 return
语句。例如
int switch_func(char c) {
switch(c) {
case 'a': return 1;
case 'b': return 3;
case 'c': return 5;
case 'd': return 7;
. . .
default: return 0;
}
}
仅当存在返回值时才减少代码。
关于c - 开关盒自动断电,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31309921/
对于我正在构建的系统,我需要一个视频编解码器,它可以承受断电 - 即,如果断电,视频仍然需要从闪存盘上剩余的内容中播放。 (车载电脑项目,拔下 key 后电脑立即关闭,如果在事故中断电)。 谁能推荐合
是否可以创建一个逻辑应用来监视特定虚拟机并发送有关断电/通电或 CPU 使用率百分比的电子邮件通知? 我已经阅读了事件网格,但它似乎更适合资源创建/删除通知,而不是特定的虚拟机信号。 我也知道可以在虚
我是一名优秀的程序员,十分优秀!