13

Summary: C++ preprocessor output includes some lines that say <built-in>. I'm curious to know what these are for.

Details:

When I compile the following code in a file named test.cpp with clang++ -E (output from g++ is similar):

#include <iostream>

int main()
{
  std::cout << "Hello World!" << std::endl;
  return 0;
}

the first few lines of output are as follows:

# 1 "test.cpp"
# 1 "test.cpp" 1
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 156 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "test.cpp" 2

My question is what do the <built-in> statements mean.

0

1 Answer 1

4

A macro expands to "1", and in case of built-in, the macro is defined by default, e.g., __cplusplus, in case of command line, the macro is defined on the command-line, i.e., -DMACRO=1.

You can see a list of predefined macros:

cpp -dM foo.h  
Sign up to request clarification or add additional context in comments.

2 Comments

it looks like I also need the -E switch to get a human readable output, at least for a .cpp file. Also does the order that the output appears correspond to which macro is applied? In the test case I included I'm trying to figure out what # 156 "<built-in>" 3 is doing.
The order corresponds to the order the macros are applied. Try the -dN flag, it should help you track that 156.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.