c - 如何使用 GNU C 预处理器预定义宏?

标签 c gcc macros cygwin

我试图弄清楚各种头文件中的整数类型定义是如何相互关联的。

我刚刚安装了 CygWin。我打开了 Cygwin\x86\usr\include\machine\_default_types.h。在其中我注意到以下代码片段:

#ifdef __INT8_TYPE__
typedef __INT8_TYPE__ __int8_t;

根据 here , __INT8_TYPE__ 是预定义的预处理器宏之一。并且:

You should not use these macros directly; instead, include the appropriate headers and use the typedefs. Some of these macros may not be defined on particular systems if GCC does not provide a stdint.h header on those systems.

所以看起来 __INT8_TYPE__ 应该在别处定义。但是我搜索了整个 CygWin 安装,没有它的定义。我发现的只是一些条件语句,就像上面的一样。

因为我不应该直接使用它。并且没有其他文件定义它。这个宏怎么会起作用呢?还是我误解了什么?

最佳答案

这是一个预定义的宏。要查看它们,您可以:

gcc -dM -E - < /dev/null

例如:

$ gcc -dM -E  - < /dev/null | grep __INT
#define __INTMAX_C(c) c ## L
#define __INT8_C(c) c
#define __INT64_C(c) c ## L
#define __INT32_MAX__ 0x7fffffff
#define __INT_FAST32_MAX__ 0x7fffffffffffffffL
#define __INT_FAST16_TYPE__ long int
#define __INT_LEAST32_MAX__ 0x7fffffff
#define __INT_FAST64_TYPE__ long int
#define __INT32_C(c) c
#define __INT_FAST32_TYPE__ long int
#define __INT16_MAX__ 0x7fff
#define __INT8_TYPE__ signed char
#define __INT_LEAST16_TYPE__ short int
#define __INT_FAST16_MAX__ 0x7fffffffffffffffL
#define __INT_LEAST16_MAX__ 0x7fff
#define __INT64_MAX__ 0x7fffffffffffffffL
#define __INT_LEAST64_TYPE__ long int
#define __INT16_TYPE__ short int
#define __INT_LEAST8_TYPE__ signed char
#define __INT_FAST8_MAX__ 0x7f
#define __INTPTR_MAX__ 0x7fffffffffffffffL
#define __INTPTR_TYPE__ long int
#define __INT_FAST64_MAX__ 0x7fffffffffffffffL
#define __INT_MAX__ 0x7fffffff
#define __INT64_TYPE__ long int
#define __INT_LEAST64_MAX__ 0x7fffffffffffffffL
#define __INT_LEAST8_MAX__ 0x7f
#define __INT_LEAST32_TYPE__ int
#define __INT_FAST8_TYPE__ signed char
#define __INTMAX_MAX__ 0x7fffffffffffffffL
#define __INT8_MAX__ 0x7f
#define __INT32_TYPE__ int
#define __INTMAX_TYPE__ long int
#define __INT16_C(c) c

关于c - 如何使用 GNU C 预处理器预定义宏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44896370/

相关文章:

c - 程序将不再找到 math.h

c - 是否可以在不搜索 malloc 语句的情况下找到分配给指针的内存

c++ - "invalid use of incomplete type"部分模板特化错误

c++ - BOOST_PREVENT_MACRO_SUBSTITUTION 应该如何工作?

c - C/C++中的仿真算法实现

c - 如何使用 strcat() 函数?

c - 嵌套范围变量的异常行为

linux - 如何配置 makefile?

c++ - 这段代码(用于容器遍历的宏)是否有效?如果是,为什么?

C# GUI 宏库或通用方法?