宏定义宏函数 if else语句报错:error: ‘else’ without a previous ‘if’(看似解决实际上没解决)
生活随笔
收集整理的這篇文章主要介紹了
宏定义宏函数 if else语句报错:error: ‘else’ without a previous ‘if’(看似解决实际上没解决)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
代碼
#include <stdio.h> #include <stdlib.h>#define ALOGE(...) { printf(__VA_ARGS__); printf("\n"); }#define fprintf(x, ...) { if(x==stderr) ALOGE(__VA_ARGS__);else fprintf(x, __VA_ARGS__); }static void usage_tip(FILE *fp, int argc, char **argv) {fprintf(fp, "Usage: %s [options]\n""Version %s\n""Options:\n""-d | --debug Debug option\n""-n | --no-mediaserver without mediaserver\n""-h | --help For help \n""\n",argv[0], "V1.0"); }int main(int argc, char **argv) {usage_tip(stderr, argc, argv);return(0); }ubuntu編譯時報錯
解決辦法
真見鬼,代碼應該是沒問題的,因為我是從RXWbrcm_patchram_plus1.c抄過來的
然后我在if語句的后一句代碼套上{}(或者去掉ALOGE(__VA_ARGS__);后的分號)就好了
#include <stdio.h> #include <stdlib.h>#define ALOGE(...) { printf(__VA_ARGS__); printf("\n"); }#define fprintf(x, ...) { if(x==stderr) {ALOGE(__VA_ARGS__);} else fprintf(x, __VA_ARGS__); }static void usage_tip(FILE *fp, int argc, char **argv) {fprintf(fp, "Usage: %s [options]\n""Version %s\n""Options:\n""-d | --debug Debug option\n""-n | --no-mediaserver without mediaserver\n""-h | --help For help \n""\n",argv[0], "V1.0"); }int main(int argc, char **argv) {usage_tip(stderr, argc, argv);return(0); }編譯運行:
總結
以上是生活随笔為你收集整理的宏定义宏函数 if else语句报错:error: ‘else’ without a previous ‘if’(看似解决实际上没解决)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 简支梁挠度计算公式推导_结构力学简支梁跨
- 下一篇: 解释型语言和编译型语言的优缺点