我正在尝试编译一个程序(我没写),我收到以下错误:
C read.c ...
In file included from read.c:6:0:
def.h:6:6: error: #elif with no expression
make: *** [read.o] Error 1
Run Code Online (Sandbox Code Playgroud)
文件def.h看起来像这样:
#ifndef TRACE_DEF
#define TRACE_DEF
#ifndef L
#define L 152064 /* (352 * 288 * 1.5) */
#elif
#error "L defined elsewhere"
#endif
#ifndef MIN
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#endif
#ifndef MAX
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#endif
Run Code Online (Sandbox Code Playgroud)
第6行就是前 一行#error "L defined elsewhere".
编译器是:
$ gcc --version
gcc-4.6.real (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Run Code Online (Sandbox Code Playgroud)
任何想法如何解决它?
Zet*_*eta 19
因为#elif期望表达式,就像#if.你想用#else.否则你必须给出表达式:
#ifndef L
#define L 152064 /* (352 * 288 * 1.5) */
#elif defined(L)
#error "L defined elsewhere"
#endif
Run Code Online (Sandbox Code Playgroud)
(当量)
#ifndef L
#define L 152064 /* (352 * 288 * 1.5) */
#else
#error "L defined elsewhere"
#endif
Run Code Online (Sandbox Code Playgroud)