繁体   English   中英

什么线路<built-in> ,<command-line> 以及在简单的 gcc -E 之后从哪里获取的 header 是什么意思?</command-line></built-in>

[英]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; }

我知道:

其他行是什么意思? 我的意思是: <built-in><command-line>以及/usr/include/stdc-predef.h是从哪里获取的?

在这里我发现了这个问题GCC 预处理,内置和命令行是干什么用的? 几乎“没有”答案。

gcc version 8.3.0 (Debian 8.3.0-6)

更新: /usr/include/stdc-predef.h的解释

header 文件 stdc stdc-predef.hgcc/config/glibc-c.c中硬编码(来自git 存储库):

 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     }

并且伪文件名"<built-in>""<command-line>"也被添加到c_finish_options中。

从一个空的 header 开始。

$ touch foo.h

您已经知道预处理器的 output 中的数字,因此不再重复。 来到<built-in> ,它是预定义宏的列表。 使用预处理器文档

-dM 代替普通的 output,为在预处理器执行期间定义的所有宏(包括预定义的宏)生成 #define 指令列表。 这为您提供了一种查找预处理器版本中预定义内容的方法。 假设你没有文件 foo.h,命令

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
:

要查看<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"

DBG显示在<command-line>集下

至于"/usr/include/stdc-predef.h" ,那是包含一些预先定义的宏的文件。 例如在我的系统上:

#ifdef __GCC_IEC_559
# if __GCC_IEC_559 > 0
#  define __STDC_IEC_559__              1
# endif

与预处理器 output 匹配:

$ gcc -E foo.h -dM|grep __STDC_IEC_559__
#define __STDC_IEC_559__ 1

您始终可以使用cpp二进制文件来进行预处理部分,而不是使用gcc -E

这个答案实际上解释了更多内容。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM