Author Topic: Problem compiling Comments  (Read 4648 times)

Offline NanoGoner

  • Single posting newcomer
  • *
  • Posts: 4
Problem compiling Comments
« on: November 27, 2012, 07:46:46 pm »
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??

Offline p2rkw

  • Almost regular
  • **
  • Posts: 142
Re: Problem compiling Comments
« Reply #1 on: November 27, 2012, 07:52:51 pm »
There's no line comment in c.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: Problem compiling Comments
« Reply #2 on: November 27, 2012, 08:10:42 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!]

Offline NanoGoner

  • Single posting newcomer
  • *
  • Posts: 4
Re: Problem compiling Comments
« Reply #3 on: November 27, 2012, 09:43:56 pm »
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.

Offline NanoGoner

  • Single posting newcomer
  • *
  • Posts: 4
Re: Problem compiling Comments
« Reply #4 on: November 27, 2012, 09:50:54 pm »
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++

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Problem compiling Comments
« Reply #5 on: November 28, 2012, 11:39:52 am »
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."