简体   繁体   English

MinGW不喜欢评论

[英]MinGW doesn't like comments

I have a compiling Problem using "code::blocks" on Windows 7. My C-code is: 我在Windows 7上使用“code :: blocks”编译问题。我的C代码是:

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

The MinGW commandline is: MinGW命令行是:

gcc.exe -Wall -g -ansi -c C:...\\Test\\main.c -o obj\\Debug\\main.o 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. 我的源文件中只有3行代码。 (The last just contains \\0 , but I didn't know, how to add a blank line). (最后只包含\\0 ,但我不知道,如何添加空白行)。 I use code::blocks as IDE. 我使用code::blocks作为IDE。 I used notepad++ to search for non-printable chars, but with no meaningful results. 我使用notepad++来搜索不可打印的字符,但没有任何有意义的结果。 I use the MinGW compiler that is available as bundled download with code::blocks. 我使用MinGW编译器作为捆绑下载提供代码:: blocks。 I corrected the "toolchain executables" and the compiler worked fine until now. 我更正了"toolchain executables" ,编译器工作正常,直到现在。

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 非常感谢Nils

Remove the compiler option -ansi . 删除编译器选项-ansi

ANSI C does not understand // . ANSI C不理解//

From the gcc documentation : gcc文档

3.4 Options Controlling C Dialect 3.4控制C语言的选项

[...] [...]

-ansi -ansi

In C mode, this is equivalent to -std=c90. 在C模式下,这相当于-std = c90。 In C++ mode, it is equivalent to -std=c++98. 在C ++模式下,它相当于-std = c ++ 98。

[...] For the C compiler, it disables recognition of C++ style '//' comments [...] [...]对于C编译器,它禁止识别C ++样式'//'注释[...]

In code blocks do this 在代码块中执行此操作

Make sure that highlighted option is unchecked.(This is same as above ans. removing -ansi. option.) 确保未选中突出显示的选项。(这与上面的ans。删除-ansi。选项相同。)

Settings->compiler

设置 - >编译

For compiling c use 用于编译c使用

/* C-style comments!
 */

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM