我只找到了這個相關的問題,這不是我想要的。
我曾經在#ifdef陳述句中定義宏:
#ifdef DEBUG
# define PRINT_IF_DEBUGGING(format) printf(format);
# define PRINTF_IF_DEBUGGING(format, ...) printf(format, __VA_ARGS__);
#else
# define PRINT_IF_DEBUGGING(...)
# define PRINTF_IF_DEBUGGING(...)
#endif
現在,我想做相反的事情,將#ifdef陳述句放在宏中。像這樣的東西:
#define PRINT_IF_DEBUGGING(format, ...) \
#if defined(DEBUG) print(format); #endif
#define PRINTF_IF_DEBUGGING(format, ...) \
#if defined(DEBUG) printf(format, __VA_ARGS__); #endif
但是,我__VA_ARGS__在#ifdef defined.
error: '#' is not followed by a macro parameter
#define PRINT_IF_DEBUGGING(format, ...)
error: '#' is not followed by a macro parameter
#define PRINTF_IF_DEBUGGING(format, ...)
warning: __VA_ARGS__ can only appear in the expansion of a C 11 variadic macro
#if defined(DEBUG) printf(format, __VA_ARGS__); #endif
這可能嗎?
uj5u.com熱心網友回復:
這確實應該是一個評論,但我無法以一種允許我說出我想說的話的方式來格式化它,所以我正在回答。
無論如何,只要改變這個:
#if defined(DEBUG) print(format); #endif
對此:
#if defined(DEBUG)
print(format);
#endif
等等,這應該可以解決它。
uj5u.com熱心網友回復:
你不能使用#ifdef inside of #define,所以不,這是不可能的。您顯示的第一個代碼是正確的解決方案。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/479439.html
上一篇:C 11延遲執行緒的執行
