Logo Questions Linux Laravel Mysql Ubuntu Git Menu

MinGW doesn't like comments

I have a compiling Problem using "code::blocks" on Windows 7. My C-code is:

 int main(void){return 0;}
//this is blank line

The MinGW commandline is:

gcc.exe -Wall -g -ansi -c C:...\Test\main.c -o obj\Debug\main.o

If i try to compile this, I get the error:

C:\...\Test\main.c|1|error: expected identifier or '(' before '/' token

(I wanted to post a picture here, but not enough reputation ...)

There are only 3 lines of code in my source file. (The last just contains \0, but I didn't know, how to add a blank line). I use code::blocks as IDE. I used notepad++ to search for non-printable chars, but with no meaningful results. I use the MinGW compiler that is available as bundled download with code::blocks. I corrected the "toolchain executables" and the compiler worked fine until now.

It's not the first time I had this problem. I remember having it on another computer before and solved it by retyping the whole source file (which I don't want to do every time).

The way the error was provoked is just commenting and uncommenting code for a while (I tried out some things and commented previous tests away). And than, out of the blue, this error appeared.

Sorry, if my grammar is bad. English is not my mother tongue.

I appreciate any given help! Thanks in advance, Nils

like image 924
Nils-o-mat Avatar asked Mar 21 '23 21:03


2 Answers

Remove the compiler option -ansi.

ANSI C does not understand //.

From the gcc documentation:

3.4 Options Controlling C Dialect



In C mode, this is equivalent to -std=c90. In C++ mode, it is equivalent to -std=c++98.

[...] For the C compiler, it disables recognition of C++ style ‘//’ comments [...]

like image 121
alk Avatar answered Apr 02 '23 11:04


In code blocks do this

Make sure that highlighted option is unchecked.(This is same as above ans. removing -ansi. option.)



like image 33
Arpit Avatar answered Apr 02 '23 10:04