我有一个像这样的宏:
#include <stdio.h>
#include <stddef.h>
#define m_test_type(e) \
do { \
if (typeof(e) == typeof(char [])) { \
printf("type is char []\n"); \
} else \
if (typeof(e) == typeof(int)) { \
printf("type is int\n"); \
} else { \
printf("type is unknown\n"); \
} \
} while (0)
int main() {
char s[] = "hello";
m_test_type(s);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在使用gcc编译期间,我收到以下错误:
prog.cpp: In function 'int main()':
prog.cpp:6:14: error: expected primary-expression before 'typeof'
if (typeof(e) == typeof(char *)) { \
^ …Run Code Online (Sandbox Code Playgroud)