这些C宏是什么意思(protos,#x?,__ unused)?

lil*_*lzz 4 c macros

#if defined(__STDC__) || defined(__cplusplus)
#define __P(protos) protos      /* full-blown ANSI C */
#define __CONCAT(x,y)   x ## y
#define __STRING(x) #x


 #define    __unused    __attribute__((__unused__))
 #define    __dead2     __attribute__((__noreturn__))
 #define    __pure2     __attribute__((__const__))
Run Code Online (Sandbox Code Playgroud)
  1. 什么protos?它在哪里定义?
  2. 什么#x
  3. 为什么需要__unused__unused__已经存在?
  4. 在哪里__const__,__noreturn__,__unused__界定?

Pot*_*ter 9

  1. protos是宏参数.它已定义,__P(protos)其范围直到行尾.在这种情况下,宏调用int func(__P(int foo))将被替换int func(int foo)为"ANSI样式"函数原型,而不是预标准C,它不一定声明函数参数.在这样的预标准编译器上,宏将被定义为没有扩展,因此编译器只会看到int func().

  2. #x是stringize运算符.它x通过添加引号将其参数的内容转换为字符串.如果传递给x包含宏的参数,则在完成字符串转换之前不会展开它们.

  3. 这些宏用于为不同的平台定义不同的东西.__unused可能在GCC或MSVC上扩展到不同的东西.

  4. 它们是编译器内部的钩子.头文件提供了编译器内部和标准语言之间的接口.编译器可以直接__unused作为扩展关键字使用,但作者更喜欢定义统一的接口__attribute__.