For a C program just before compilation, i.e. after the pre-processing has been completed which file(what extension) is generated?
-
1None? Usually (as far as I know) it's just kept in memory or piped to another program, so there is no file. – Cornstalks Jan 27 '15 at 19:53
-
2*if* an actual file was created (which is usually done only when a compiler switch is set that tells it to do so), the filename to use for the preprocessed output is usually provided along with that switch being set. If the filename is automatically assigned, it would depend on which compiler you're using on which OS (neither of which you provided to us). – Ken White Jan 27 '15 at 19:54
-
1This is the kind of thing that depends on your compiler toolchain. With some (e.g. gcc), you can ask for that file, in which case you provide a name. – juanchopanza Jan 27 '15 at 19:54
-
Highly related: http://stackoverflow.com/questions/277258/c-c-source-file-after-preprocessing?rq=1 – OJFord Jan 27 '15 at 19:58
4 Answers
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
.

- 142,963
- 15
- 272
- 331
In most current compilers (e.g. GCC or Clang/LLVM) - and for performance reasons - the C/C++ preprocessor is an internal part of the compiler (in GCC it is libcpp/ and is a library ...), so no preprocessed form is output into a file.
In the very first C or proto-C compilers (1970s PDP-8) the memory was so small (64kilobytes!) that such an organization was not possible, and the preprocessor was a separate program /lib/cpp
Today, our laptops have several gigabytes of memory, which is usually much larger than the preprocessed form (of the largest source file you'll feed to your compiler). So current compilers keep some internal representation of the whole translation unit and are able to optimize it entirely (inter-procedural optimizations, including inlining).
All compilers keep several forms of the abstract syntax tree (AST); the bulk of the work of a compiler is not parsing or code generation, but transforming some internal representation of the AST into another internal representation (itself further transformed). In GCC most of the optimizations are working on the GIMPLE form. You can extend the compiler by adding your own optimization passes, e.g. with your GCC plugin.
In turn, this technological evolution has fertilized the (evolution of) the definition of our programming languages, recent C++11 is designed for a very optimizing compiler. The recent style guiding or coding hints around C++11 are presupposing (and makes sense only because of) very powerful optimizations.
You still can usually invoke the compiler to spit the preprocessed form, e.g. with gcc -C -E source.c > source.i
, in a seperate file (conventionally suffixed .i
or .ii
, and such suffixes can be known to builder like make
)

- 223,805
- 18
- 296
- 547
Journey of a C Program to Linux Executable in 4 Stages :
- Pre-processing
- Compilation
- Assembly
- Linking
Check this link for more details C program compilation process

- 37
- 1
- 6
>gcc -E fname.c >fname.x
/fname.x is the pre-processed output to which u r saving/
The following four things happen in the pre-processing stage.
1> header file inclusion
2>comment removal
3>macro substitution
(eg if u have #fenine NUM 10, where-ever in code you have used NUM ll be replaced by 10)
4> conditional compilation
(eg
#if 0
...
some code
...
#endif
since "#if 0" evaluates to 0, the code under it never executes. Therefore code under it is not included in your pre-processed output

- 59
- 1
- 4