c - _never_executed() 的目的?

标签 c embedded c-preprocessor intrinsics

我以前见过这个宏的定义,但从来不知道它的用途。谁能阐明这一点?

最佳答案

这是用于优化的编译器内在函数,通常出现在嵌入式编程中。我唯一一次看到它使用是在 switch 语句的“默认”中断言变量的范围有限(为了更好的优化)。示例:

 /* Get DTMF index */
 switch(dtmf)
 {
     case '0':
     case '1':
     case '2':
     case '3':
     case '4':
     case '5':
     case '6':
     case '7':
     case '8':
     case '9':
         /* Handle numeric DTMF */
         index = dtmf - '0';
         break;
     case 'A':
     case 'B':
     case 'C':
     case 'D':
         index = dtmf - 'A' + 10;
         break:
     default:
         _never_executed();
         break;
 }

可能不适用于所有编译器...

关于c - _never_executed() 的目的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/208272/

相关文章:

c - 外部数组,如何使用

c - Visual Studio 将不完整数组视为零长度数组

c++ - arm 裸机系统上的 CPU 使用率测量

c - Arduino (AVR ATMega328) Timer1 似乎没有在正确的时间触发

保留换行符的 C++ 预处理器字符串化?

c - 不要从 char palindrome[] 中获取输出

c - 二叉树的标记化问题

java - 无法使用内置的 BrokerService.stop 调用关闭嵌入式 activeMQ 服务

检查定义 GNU C

c++ - Doxygen 文档注释#define