Home > Backend Development > C++ > body text

Convert C/C++ programs to preprocessor code

王林
Release: 2023-09-11 16:21:07
forward
664 people have browsed it

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.

Syntax

g++ -E program.cpp
Copy after login

Example

<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>
Copy after login

Output

$ g++ -E test_prog.cpp
int main() {
   float a = 3.1415, r = 5;
   float c = a * r * r;
   return 0;
}
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!