// Comments not working

Hello.

I'm having a strange problem. When trying to write comments with the double forward slash // in C, I get a compiler error. It says something like "error: expected expression before //". This problem has come from nowhere as the // has always worked before. Also, I do not get an error when I use /*...*/ for comments, however it would be impractical to use that for every little comment I want to make.

Any help with this matter would be much appreciated.
What version of C are you using? I'm 99% sure that "// comments" don't exist in earlier standards of C, only the /* */ delimiters exist.

Edit: Yup, only C99 (and later) support //.
Last edited on
Thanks for the reply. Do you know how I can change the version of C I'm using? I can't find the option in Code::Blocks.

Edit:
Here is the full compiler error.

||=== Build: Debug in a (compiler: GNU GCC Compiler) ===|
C:\Users\dell\Desktop\a\main.c||In function 'main':|
C:\Users\dell\Desktop\a\main.c|6|error: expected expression before '/' token|
C:\Users\dell\Desktop\a\main.c|8|warning: control reaches end of non-void function [-Wreturn-type]|
||=== Build failed: 1 error(s), 1 warning(s) (0 minute(s), 0 second(s)) ===|

Edit 2:
It's okay, I figured it out. It was just a simple compiler flag option I had enabled telling the compiler to support C90 programs. Unticking it has solved the // comments problem.

Thank you again for your help.
Last edited on
Registered users can post here. Sign in or register to post.