cpp output: "<built-in>", "<command-line>"

Hi

When I look at the cpp output, I see
1
2
3
4
5
6
7
8
$ cat cpp_mymain
# 1 "mymain.cc"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "mymain.cc"
int main(){
 return 0;
}


What are 'built-in' and 'command-line'?

Normally when I include a header like <iostream> I get a huge amount of code pulled in. If these are headers, why aren't they expanded like <iostream>?
It's sort of trying to let you know what's defined where.

Use this x.cpp:
1
2
3
4
5
6
#define TEST 100

int main()
{
	return 0;
}


The run:
 
cpp -DPROG=1 -dD x.cpp
Thanks
So <built-in> and <command-line> aren't files (I think '-' is an invalid character in a filename, anyway)?
There not files. They're markers to show where the definitions have come from. In a sophisticated build environment, it's not always clear what's defined where.
Last edited on
There are lots of built-in #defines like
#define __INT_MAX__ 2147483647
Is it okay to use these instead of the header <limits>?
Last edited on
Not really. The whole point of using C (as opposed to assembler) is to write portable code. So you should opt for a standard where it exists.
Not really. The whole point of using C (as opposed to assembler) is to write portable code. So you should opt for a standard where it exists.


That makes sense. Thanks again!

Duoas:
Yes I've read that page but it doesn't mention what I was asking about.
Well, you posted about what the CPP does and asked, "What are 'built-in' and 'command-line'?" and, "If these are headers, why aren't they expanded like <iostream>?". The link I gave you answers those questions directly. What exactly did I miss?
I read through it again but I don't see what I could gather from it. The lines in question do follow the form of #linenumber filename, but 'built-in' and 'command-line' aren't file names.

It also says that "all preprocessing directive lines have been replaced with blank lines". There are no blank lines corresponding to all the <built-in> and <command-line> #defines.

 Quoth the CPP Manual:
Long runs of blank lines are discarded.


What you have, as explained at the bottom, are directives to the GCC explaining where to get information. This is the limit of my knowledge about it, but it is a very good starting point to learn more.

My guess is that you #include <iostream> , for example, and the CPP turns it into what you see. I'm not even going to bother testing my hypothesis, because right or wrong I just don't care more than that. You'll have to dig down in GCC documentation and/or source to learn more.
Topic archived. No new replies allowed.