当我搜索__cplusplus
的含义时,我发现了一段代码如下。
#include <stdio.h>
int main() {
#define TO_LITERAL(text) TO_LITERAL_(text)
#define TO_LITERAL_(text) #text
#ifndef __cplusplus
/* this translation unit is being treated as a C one */
printf("a C program\n");
#else
// this translation unit is being treated as a C++ one
printf("a C++ program\n__cplusplus expands to \""
TO_LITERAL(__cplusplus) "\"\n");
#endif
(void)getchar();
return 0;
}
此代码根据编译方式提供不同的输出。但我不太了解两条粗线。
#define TO_LITERAL(text) #text
非常感谢