News:

When registered with our forums, feel free to send a "here I am" post here to differ human beings from SPAM bots.

Main Menu

Problem compiling Comments

Started by NanoGoner, November 27, 2012, 07:46:46 PM

Previous topic - Next topic

NanoGoner

I have been trying to compile a C program using "//" for comments.  The error message for the line

// 3d.c

is

"exected identifier or '(' before '/' token"

If I change the line to

/* 3d.c */

it compiles fine.  Can anyone tell me what's going on??

p2rkw


oBFusCATed

Quote from: p2rkw on November 27, 2012, 07:52:51 PM
There's no line comment in c.
This is partially true, because they are supported in C99 mode.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

NanoGoner

Thank you both.  I presume by C99 mode you mean C++.  Can you tell me how to switch modes.  I can't find it in the manual.

NanoGoner

Thank you both.  I presume by C99 mode you mean C++.  Can you tell me how to switch modes.  I can't find it in the manual.
There's nothing in the code that wouldn't compile under C++

thomas

Well, if your code is C++, rename the file to cpp or cxx or cc, but "nothing in the code that wouldn't compile under C++" is not really the same.

If your code is C, that is iso9899:1990 unless you specify something different. In that case, it should be C90 and not something else. On the other hand, if you need C99 features, you must use a compiler that supports this language revision (not all do), and you must tell the compiler.

GCC supports C99 if you add -std=c99 to the command line.

Note that some broken compilers (such as Microsoft) support C++ comments despite not properly supporting C99. That's because they use the C++ compiler (with some tweaks) to compile C, which accidentially works, although it shouldn't.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."