這個問題在這里已經有了答案: 編譯器通過這個宏看到了什么?[關閉] (4 個回答) 7 小時前關閉。
我遇到了這個宏:
#define STR_ERROR(ecode) case ecode: return #ecode;
什么是#ecode部分呢?
ecode 是一個 int,這個函式回傳一個 const char*。
我確定這已經得到了回答,但是我的 search-foo 已經放棄了我。ecode本身特定于此代碼。搜索c #提供有關宏的一般資訊(以及一些與 C 相關的編號串列)。
uj5u.com熱心網友回復:
根據cppreference:
# 替換串列中識別符號之前的運算子通過引數替換運行識別符號并將結果括在引號中,有效地創建了一個字串文字
Microsoft Docs 中的示例
#include <stdio.h>
#define stringer( x ) printf_s( #x "\n" )
int main() {
stringer( In quotes in the printf function call );
stringer( "In quotes when printed to the screen" );
stringer( "This: \" prints an escaped double quote" );
}
結果:
In quotes in the printf function call
"In quotes when printed to the screen"
"This: \" prints an escaped double quote"
Google-Fu protip : 我剛剛搜索了C macro #,Google 建議operator在最后添加,那些檔案在第一頁。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/328469.html
上一篇:什么時候實體化模板?
下一篇:除錯斷言失敗-C ,使用智能指標
