How to See a C/C++ Source File After Preprocessing in Visual Studio

How do I see a C/C++ source file after preprocessing in Visual Studio?

cl.exe, the command line interface to Microsoft Visual C++, has three different options for outputting the preprocessed file (hence the inconsistency in the previous responses about Visual C++):

  • /E: preprocess to stdout (similar to GCC's -E option)
  • /P: preprocess to file
  • /EP: preprocess to stdout without #line directives

If you want to preprocess to a file without #line directives, combine the /P and /EP options.

How can I see the output of the Visual C++ preprocessor? [duplicate]

cl.exe, the command line interface to Microsoft Visual C++, has three different options for outputting the preprocessed file (hence the inconsistency in the previous responses about Visual C++):

  • /E: preprocess to stdout (similar to GCC's -E option)
  • /P: preprocess to file
  • /EP: preprocess to stdout without #line directives

(copied directly from https://stackoverflow.com/a/277362/3279)

Parsing a C++ source file after preprocessing

You realize that g++ -E adds some of its own lines to its output which indicate line numbers in the original file? You'll find lines like

# 2 "foo.cc" 2

which indicate that you're looking at line 2 of file foo.cc . These lines are inserted whenever the regular sequence of lines is disrupted.

show resulting c/c++ files after including headers (before translation to machine language) [duplicate]

On Linux use -E gcc option. It will print the "big" source code to stdout, allowing you to redirect it to a file.

On Visual Studio use the following options: /E for stdout or /P to print to a file.

By the way, your questions were already asked separately:

  • Linux/GCC
  • Visual Studio

Those *.i files are exactly what you asked for, as you get one *.i file per one *.cpp file. You'll get the same on GNU compilers if you feed a single source file to gcc -E. An *.i file is a *.cpp file with all include completely unrolled. I suppose your C++ files included standard library headers directly or indirectly through other includes, so you got lots of scary-looking code in your preprocessed files. Nevertheless, it's still C++, and it's somewhat more "pure" C++ than what you have in your sources. Visual Studio preprocessor also includes #line directives to it's output. They will be used by compiler to report correct line numbers on compilation errors. You may suppress them with /EP.

To check that everything is correct you may create an empty project and play with a few of your own source and headers files without including any standard library or third-party headers.

Which file is generated after preprocessing of a C program?

It is compiler dependent. Most compilers by default don't generate intermediate pre-processor files.

With gcc, if you add -save-temps option to get the intermediate files, the output of the pre-processor is dumped in a .i file. With -E option (to perform only the pre-processing), without -o to specify the output file, the result is dumped to stdout.

Can gcc output C code after preprocessing?

Yes. Pass gcc the -E option. This will output preprocessed source code.

How to check (via the preprocessor) if a C source file is being compiled as C++ code

#ifndef __cplusplus

If I remember correctly.

See what the preprocessor is doing

For gcc just use the -E switch

gcc -E

-E Stop after the preprocessing stage; do not run the compiler proper.
The output is in the form of
preprocessed source code, which is
sent to the standard output.



Related Topics



Leave a reply



Submit