Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

g++ preprocessor output [closed]

I want to get only preprocessed version of file.cc. I did g++ -E file.cc, got:

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

What did I do wrong?

like image 323
mirt Avatar asked Sep 19 '12 06:09

mirt


People also ask

What is the output of pre processors?

In computer science, a preprocessor (or precompiler) is a program that processes its input data to produce output that is used as input to another program. The output is said to be a preprocessed form of the input data, which is often used by some subsequent programs like compilers.

Where does the output from the preprocessor go?

When the C preprocessor is used with the C, C++, or Objective-C compilers, it is integrated into the compiler and communicates a stream of binary tokens directly to the compiler's parser. However, it can also be used in the more conventional standalone mode, where it produces textual output.

What is preprocessed source code?

The preprocessor is a text substitution tool that modifies the source code before the compilation takes place. This modification is done according to the preprocessor directives that are included in the source files.

Which command is used to check preprocessed code?

4.3 Preprocessing source files If this file is called 'test. c' the effect of the preprocessor can be seen with the following command line: $ gcc -E test. c # 1 "test.


1 Answers

Assumed that your source file contains a simple main function:

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

Then, with the command you showed, the output looks like this:

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

int main() {
    return 0;
}

The output which is shown in the question happens when file.cc is empty. Note that "empty" means that the file can still contain comments, or #ifdef blocks with a condition which evaluates to false - since the preprocessor filters them out, they do not appear in the output either.

like image 119
Andreas Fester Avatar answered Sep 19 '22 18:09

Andreas Fester