什么行 <built-in>、<command-line> 以及 header 在简单 gcc -E 之后的意思是什么?
What lines <built-in>, <command-line> and from where a header it taken after simple gcc -E means?
main.c:
int main() { return 0; }
预处理阶段后: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; }
我知道:
- 第一个数字是已处理文件的行号;
- “字符串”是文件名;
- 行尾的数字在这里描述 https://gcc.gnu.org/onlinedocs/cpp/Preprocessor-Output.html
其他几行是什么意思?我的意思是:<built-in>
、<command-line>
以及 /usr/include/stdc-predef.h
的来源?
我在这里找到了这个问题 GCC preprocessing, what are the built-in and command-line lines for? 几乎“没有”答案。
gcc version 8.3.0 (Debian 8.3.0-6)
更新:/usr/include/stdc-predef.h
的解释
header 文件 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 }
在gcc/c-family/c-opts.c
的push_command_line_include
处理:
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 }
和pseudo-filenames"<built-in>"
和"<command-line>"
也在c_finish_options
中添加。
从空 header 开始。
$ touch foo.h
您已经知道预处理器输出中的数字,所以不会 re-iterate。来到<built-in>
,这是预定义宏的列表。使用 preprocessor documentation
-dM Instead of the normal output, generate a list of #define
directives for all the macros defined during the
execution of the preprocessor, including predefined
macros. This gives you a way of finding out what is
predefined in your version of the preprocessor. Assuming
you have no file foo.h, the command
touch foo.h; cpp -dM foo.h
shows all the predefined macros.
所以,这样做应该会给出所有预定义的宏及其扩展:
#define __SSP_STRONG__ 3
#define __DBL_MIN_EXP__ (-1021)
#define __FLT32X_MAX_EXP__ 1024
#define __UINT_LEAST16_MAX__ 0xffff
#define __ATOMIC_ACQUIRE 2
:
要查看 <command-line>
是如何扩展的,请使用 -DX=Y
语法传入 command-line 定义
$ 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"
DBG
出现在 <command-line>
组
下
至于 "/usr/include/stdc-predef.h"
,那是包含其中一些 pred-defined 宏的文件。例如在我的系统上:
#ifdef __GCC_IEC_559
# if __GCC_IEC_559 > 0
# define __STDC_IEC_559__ 1
# endif
与 pre-processor 输出匹配:
$ gcc -E foo.h -dM|grep __STDC_IEC_559__
#define __STDC_IEC_559__ 1
您始终可以使用 cpp
二进制文件来完成 pre-processing 部分,而不是使用 gcc -E
.
this 答案中实际上解释了更多内容。
main.c:
int main() { return 0; }
预处理阶段后: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; }
我知道:
- 第一个数字是已处理文件的行号;
- “字符串”是文件名;
- 行尾的数字在这里描述 https://gcc.gnu.org/onlinedocs/cpp/Preprocessor-Output.html
其他几行是什么意思?我的意思是:<built-in>
、<command-line>
以及 /usr/include/stdc-predef.h
的来源?
我在这里找到了这个问题 GCC preprocessing, what are the built-in and command-line lines for? 几乎“没有”答案。
gcc version 8.3.0 (Debian 8.3.0-6)
更新:/usr/include/stdc-predef.h
header 文件 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 }
在gcc/c-family/c-opts.c
的push_command_line_include
处理:
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 }
和pseudo-filenames"<built-in>"
和"<command-line>"
也在c_finish_options
中添加。
从空 header 开始。
$ touch foo.h
您已经知道预处理器输出中的数字,所以不会 re-iterate。来到<built-in>
,这是预定义宏的列表。使用 preprocessor documentation
-dM Instead of the normal output, generate a list of #define directives for all the macros defined during the execution of the preprocessor, including predefined macros. This gives you a way of finding out what is predefined in your version of the preprocessor. Assuming you have no file foo.h, the command
touch foo.h; cpp -dM foo.h
shows all the predefined macros.
所以,这样做应该会给出所有预定义的宏及其扩展:
#define __SSP_STRONG__ 3
#define __DBL_MIN_EXP__ (-1021)
#define __FLT32X_MAX_EXP__ 1024
#define __UINT_LEAST16_MAX__ 0xffff
#define __ATOMIC_ACQUIRE 2
:
要查看 <command-line>
是如何扩展的,请使用 -DX=Y
语法传入 command-line 定义
$ 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"
DBG
出现在 <command-line>
组
至于 "/usr/include/stdc-predef.h"
,那是包含其中一些 pred-defined 宏的文件。例如在我的系统上:
#ifdef __GCC_IEC_559
# if __GCC_IEC_559 > 0
# define __STDC_IEC_559__ 1
# endif
与 pre-processor 输出匹配:
$ gcc -E foo.h -dM|grep __STDC_IEC_559__
#define __STDC_IEC_559__ 1
您始终可以使用 cpp
二进制文件来完成 pre-processing 部分,而不是使用 gcc -E
.
this 答案中实际上解释了更多内容。