Home > Article > Backend Development > Convert C/C++ programs to preprocessor code
Here we will see how to generate preprocessing or preprocessor code from the source code of a C or C program.
To view the preprocessed code using the g compiler, we must use the '-E ' option with g .
The preprocessor contains all # directives in the code and also extends the MACRO function.
g++ -E program.cpp
<span class="com">#define</span><span class="pln"> PI </span><span class="lit">3.1415</span> <span class="kwd">int</span><span class="pln"> main</span><span class="pun">()</span><span class="pln"> </span><span class="pun">{</span> <span class="kwd"> float</span><span class="pln"> a </span><span class="pun">=</span><span class="pln"> PI</span><span class="pun">,</span><span class="pln"> r </span><span class="pun">=</span><span class="pln"> </span><span class="lit">5</span><span class="pun">;</span> <span class="kwd"> float</span><span class="pln"> c </span><span class="pun">=</span><span class="pln"> a </span><span class="pun">*</span><span class="pln"> r </span><span class="pun">*</span><span class="pln"> r</span><span class="pun">;</span> <span class="kwd"> return</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span> <span class="pun">}</span>
$ g++ -E test_prog.cpp int main() { float a = 3.1415, r = 5; float c = a * r * r; return 0; }
The above is the detailed content of Convert C/C++ programs to preprocessor code. For more information, please follow other related articles on the PHP Chinese website!