I am using gcc
(Ubuntu 4.4.1-4ubuntu9) to compile a program that I'm writing, but it seems to vomit whenever it sees a // comment in my code, saying:
我正在使用gcc (Ubuntu 4.4.1-4ubuntu9)编译一个我正在编写的程序,但是每当它看到我的代码中的一个//注释时,它就会吐出来,说:
interface.c :##: error: expected expression before â/â token<
Does the gcc
compile mode I'm using forbid //
comments?
我使用的gcc编译模式是禁止的吗?
$ gcc -g -ansi -pedantic interface.c structs.h -c -I. -I/home/me/project/h
Why?
为什么?
3 个解决方案
#1
64
//
comments are not allowed in old (pre 99) C versions, use /**/
(or remove the -ansi
, that is a synonym for the C89 standard)
//注释不允许使用旧的(pre - 99) C版本,使用/**/(或删除-ansi,这是C89标准的同义词)
#2
21
See C++ comments in GNU compiler documentation.
参见GNU编译器文档中的c++注释。
In GNU C, you may use C++ style comments, which start with
//
and continue until the end of the line. Many other C implementations allow such comments, and they are included in the 1999 C standard. However, C++ style comments are not recognized if you specify an-std
option specifying a version of ISO C beforeC99
, or-ansi
(equivalent to-std=c89
).在GNU C中,您可以使用c++风格的注释,它从//开始直到行结束。许多其他的C实现允许这样的注释,并且它们包含在1999年的C标准中。但是,如果您在C99或-ansi(等效于-std=c89)之前指定一个-std选项指定一个版本的ISO C,那么c++风格的注释就不会被识别。
(Emphasis is mine because some of the posts claim that //
are not allowed in standard C whereas that is only true for pre-99 standards).
(强调是我的,因为有些帖子声称//不允许在标准C中,而这只适用于99年前的标准)。
#3
3
//
comments are actually a C++ feature in origin, which is why -ansi
disables them.
//注释实际上是一个c++特性,这就是为什么-ansi禁用它们的原因。
#1
64
//
comments are not allowed in old (pre 99) C versions, use /**/
(or remove the -ansi
, that is a synonym for the C89 standard)
//注释不允许使用旧的(pre - 99) C版本,使用/**/(或删除-ansi,这是C89标准的同义词)
#2
21
See C++ comments in GNU compiler documentation.
参见GNU编译器文档中的c++注释。
In GNU C, you may use C++ style comments, which start with
//
and continue until the end of the line. Many other C implementations allow such comments, and they are included in the 1999 C standard. However, C++ style comments are not recognized if you specify an-std
option specifying a version of ISO C beforeC99
, or-ansi
(equivalent to-std=c89
).在GNU C中,您可以使用c++风格的注释,它从//开始直到行结束。许多其他的C实现允许这样的注释,并且它们包含在1999年的C标准中。但是,如果您在C99或-ansi(等效于-std=c89)之前指定一个-std选项指定一个版本的ISO C,那么c++风格的注释就不会被识别。
(Emphasis is mine because some of the posts claim that //
are not allowed in standard C whereas that is only true for pre-99 standards).
(强调是我的,因为有些帖子声称//不允许在标准C中,而这只适用于99年前的标准)。
#3
3
//
comments are actually a C++ feature in origin, which is why -ansi
disables them.
//注释实际上是一个c++特性,这就是为什么-ansi禁用它们的原因。