nwa*_*thi -2 c macros syntax-error
这是我的代码,我不知道我哪里错,什么是"表达"?
#define m(smth) (if(sizeof(smth) == sizeof(int)) {printf("%d", (int) smth);} else{puts((char*)smth);})
int main(void) {
m("smth");
}
Run Code Online (Sandbox Code Playgroud)
这是输出:
/home/roroco/Dropbox/rbs/ro_sites/c/ex/ex2.c: In function ‘main’:
/home/roroco/Dropbox/rbs/ro_sites/c/ex/ex2.c:18:18: error: expected expression before ‘if’
#define m(smth) (if(sizeof(smth) == sizeof(int)) {printf("%d", (int) smth);} else{puts((char*)smth);})
^
/home/roroco/Dropbox/rbs/ro_sites/c/ex/ex2.c:21:5: note: in expansion of macro ‘m’
m("smth");
^
make[3]: *** [ex/CMakeFiles/ex2.dir/ex2.c.o] Error 1
make[2]: *** [ex/CMakeFiles/ex2.dir/all] Error 2
make[1]: *** [ex/CMakeFiles/ex2.dir/rule] Error 2
make: *** [ex2] Error 2
Run Code Online (Sandbox Code Playgroud)
(if(expression) {} else {}) 是无效的语法.
尝试
#define m(smth) if(sizeof(smth) == sizeof(int)) {printf("%d", (int) smth);} else{puts((char*)smth);}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3004 次 |
| 最近记录: |