6

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

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.

任何想法如何解决它?

4

1 回答 1

22

因为#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
于 2013-03-04T15:00:26.370 回答