如何使用GNU C预处理器预定义的宏? [英] How are the GNU C preprocessor predefined macros used?
问题描述
我试图弄清楚各种头文件中的整数类型定义是如何相互关联的.
I am trying to figure out how the integer type definitions from various header files are related to each other.
我刚刚安装了CygWin.我打开了Cygwin\x86\usr\include\machine\_default_types.h
.在其中,我注意到了以下代码片段:
I just installed the CygWin. I opened the Cygwin\x86\usr\include\machine\_default_types.h
. In it I noticed below code snippets:
#ifdef __INT8_TYPE__
typedef __INT8_TYPE__ __int8_t;
根据此处,__INT8_TYPE__
为预定义的预处理器宏之一.并且:
According to here, the __INT8_TYPE__
is one of the predefined pre-processor macros. And:
您不应直接使用这些宏;相反,包括 适当的标头,并使用typedef.其中一些宏可能不会 如果GCC不提供stdint.h,则在特定系统上定义 这些系统上的标题.
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安装,但没有定义.我发现的只是一些条件语句,就像上面的语句一样.
So it seems the __INT8_TYPE__
should be defined somewhere else. But I searched the whole CygWin installation, there's no definition for it. All I found are some conditional statements just like above one.
因为我不应该直接使用它.而且没有其他文件在定义它.这个宏如何生效?还是我误会了什么?
Since I shouldn't use it directly. And no other files are defining it. How could this macro ever come into action? Or did I misunderstand something?
推荐答案
这是预定义的宏.要查看它们,您可以:
This is a predefined macro. To see them you can:
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
这篇关于如何使用GNU C预处理器预定义的宏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!