ede*_*dem 2 c gcc c-preprocessor
主文件:
int main() { return 0; }
Run Code Online (Sandbox Code Playgroud)
预处理阶段后: gcc -E main.c
# 1 "main.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 31 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 32 "<command-line>" 2
# 1 "main.c"
int main() { return 0; }
Run Code Online (Sandbox Code Playgroud)
我知道:
其他线路是什么意思?我的意思是:<built-in>,<command-line>从哪里/usr/include/stdc-predef.h采取?
在这里我发现了这个问题GCC 预处理,内置和命令行有什么用?几乎“没有”的答案。
gcc version 8.3.0 (Debian 8.3.0-6)
Run Code Online (Sandbox Code Playgroud)
更新:解释 /usr/include/stdc-predef.h
头文件stdc-predef.h被硬编码在gcc/config/glibc-c.c(来自git repo):
26 /* Implement TARGET_C_PREINCLUDE for glibc targets. */
27
28 static const char *
29 glibc_c_preinclude (void)
30 {
31 return "stdc-predef.h";
32 }
Run Code Online (Sandbox Code Playgroud)
它在处理push_command_line_include的gcc/c-family/c-opts.c:
1534 /* Give CPP the next file given by -include, if any. */
1535 static void
1536 push_command_line_include (void)
1537 {
1538 /* This can happen if disabled by -imacros for example.
1539 Punt so that we don't set "<command-line>" as the filename for
1540 the header. */
1541 if (include_cursor > deferred_count)
1542 return;
1543
1544 if (!done_preinclude)
1545 {
1546 done_preinclude = true;
1547 if (flag_hosted && std_inc && !cpp_opts->preprocessed)
1548 {
1549 const char *preinc = targetcm.c_preinclude ();
1550 if (preinc && cpp_push_default_include (parse_in, preinc))
1551 return;
1552 }
1553 }
Run Code Online (Sandbox Code Playgroud)
和伪文件名"<built-in>","<command-line>"也添加在c_finish_options那里。
从一个空的标题开始。
$ touch foo.h
Run Code Online (Sandbox Code Playgroud)
您已经知道预处理器输出中的数字,因此不再重复。来到<built-in>,它是预定义宏的列表。使用预处理器文档
-dM 代替正常输出,为预处理器执行期间定义的所有宏生成#define 指令列表,包括预定义的宏。这使您可以找出预处理器版本中预定义的内容。假设你没有文件 foo.h,命令
Run Code Online (Sandbox Code Playgroud)touch foo.h; cpp -dM foo.h显示所有预定义的宏。
因此,这样做应该使所有预定义的宏及其扩展为:
#define __SSP_STRONG__ 3
#define __DBL_MIN_EXP__ (-1021)
#define __FLT32X_MAX_EXP__ 1024
#define __UINT_LEAST16_MAX__ 0xffff
#define __ATOMIC_ACQUIRE 2
:
Run Code Online (Sandbox Code Playgroud)
要查看如何<command-line>展开,请使用以下-DX=Y语法传入命令行定义
$ gcc -E -DDBG=1 -dN foo.h|grep 'command-line' -A 1 -B 1
#define __DECIMAL_BID_FORMAT__
# 1 "<command-line>"
#define DBG
-- #define __STDC_ISO_10646__
# 1 "<command-line>" 2
# 1 "foo.h"
Run Code Online (Sandbox Code Playgroud)
DBG出现在<command-line>集合下
至于"/usr/include/stdc-predef.h",那是包含一些预定义宏的文件。例如在我的系统上:
#ifdef __GCC_IEC_559
# if __GCC_IEC_559 > 0
# define __STDC_IEC_559__ 1
# endif
Run Code Online (Sandbox Code Playgroud)
与预处理器输出匹配:
$ gcc -E foo.h -dM|grep __STDC_IEC_559__
#define __STDC_IEC_559__ 1
Run Code Online (Sandbox Code Playgroud)
您始终可以使用cpp二进制文件来执行预处理部分,而不是使用gcc -E.
在这个答案中实际上解释了更多。