这里我们将看到如何从 C 或 C++ 程序的源代码生成预处理或预处理器代码。
要使用 g++ 编译器查看预处理代码,我们必须使用 '-E ' 选项与 g++。
预处理器包含代码中的所有 # 指令,并且还扩展了 MACRO 函数。
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; }
以上是将C/C++程序转换为预处理器代码的详细内容。更多信息请关注PHP中文网其他相关文章!