G ++ preprocessor output

I want to get only the pre-processed version file.cc. I did g++ -E file.cc, received:

# 1 "file.cc"
# 1 "<command-line>"
# 1 "file.cc"

What have I done wrong?

+5
source share
2 answers

Your source file is supposed to contain a simple core function:

$ cat file.cc
int main() {
    return 0;
}

Then, using the command you showed, the result is as follows:

$ g++ -E file.cc
# 1 "file.cc"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "file.cc"

int main() {
    return 0;
}

The result that appears in the question occurs when it is file.ccempty. Note that โ€œemptyโ€ means that the file can still contain comments or #ifdefblocks with a condition that evaluates to false - since the preprocessor filters them, they also do not appear on the output.

+10
source

, -P:

-P
    Inhibit generation of linemarkers in the output from the preprocessor. This might
    be useful when running the preprocessor on something that is not C code, and will
    be sent to a program which might be confused by the linemarkers. 
+4

All Articles