“没有表达的#elif”是什么意思?

时间:2013-03-04 14:58:38

标签: c gcc

我正在尝试编译一个程序(我没写过),我收到以下错误:

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

文件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

第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.

任何想法如何解决?

1 个答案:

答案 0 :(得分:19)

因为#elif需要一个表达式,就像#if一样。您想使用#else。否则你必须给出表达式:

#ifndef L
  #define L 152064 /* (352 * 288 * 1.5) */
#elif defined(L)
  #error "L defined elsewhere"
#endif

(当量)

#ifndef L
  #define L 152064 /* (352 * 288 * 1.5) */
#else
  #error "L defined elsewhere"
#endif