edem
edem

Reputation: 3272

What lines <built-in>, <command-line> and from where a header it taken after simple gcc -E means?

main.c:

int main() { return 0; }

After preprocessing stage: 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; }

I know that:

What does other lines mean? I mean: <built-in>, <command-line> and from where /usr/include/stdc-predef.h is taken?

Here I found this question GCC preprocessing, what are the built-in and command-line lines for? almost "without" answers.

gcc version 8.3.0 (Debian 8.3.0-6)

UPDATED: Explanation of /usr/include/stdc-predef.h

The header file stdc-predef.h was hardcoded in gcc/config/glibc-c.c (from 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 }

It is processed in push_command_line_include of 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     }

and pseudo-filenames "<built-in>" and "<command-line>" are added in c_finish_options there also.

Upvotes: 5

Views: 467

Answers (1)

Zoso
Zoso

Reputation: 3465

Start with an empty header.

$ touch foo.h

You are already aware of the numbers in the output of the preprocessor, so won't re-iterate. Coming to <built-in>, it is the list of the predefined macros. Using the 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.

So, doing that should give all the predefined macros and their expanions as:

#define __SSP_STRONG__ 3
#define __DBL_MIN_EXP__ (-1021)
#define __FLT32X_MAX_EXP__ 1024
#define __UINT_LEAST16_MAX__ 0xffff
#define __ATOMIC_ACQUIRE 2
:

To see how <command-line> is expanded, pass in a command-line define using the -DX=Y syntax

$ 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 shows up under the <command-line> set

As for "/usr/include/stdc-predef.h", well that's the file that contains some of those pred-defined macros. e.g on my system:

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

which matches with the pre-processor output:

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

You can always use the cpp binary for just doing the pre-processing part instead of using gcc -E.

A lot more is actually explained in this answer.

Upvotes: 5

Related Questions