這裡我們將看到如何從 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中文網其他相關文章!