开发者

Why can't I use //-style comments in my C code?

开发者 https://www.devze.com 2022-12-19 18:40 出处:网络
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:

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:

interface.c :##: error: expected expression before â/â token<

Does the gcc compile mode I'm using forbid // comments?

$ gcc -g -ansi -pedantic interface.c structs.h -c -I. -I/home开发者_运维问答/me/project/h

Why?


// comments are not allowed in old (pre 99) C versions, use /**/ (or remove the -ansi, that is a synonym for the C89 standard)


See C++ comments in GNU compiler documentation.

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 before C99, or -ansi (equivalent to -std=c89).

(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).

0

精彩评论

暂无评论...
验证码 换一张
取 消