![](/img/trans.png)
[英]ISO C90 forbids mixed declarations and code because of arrays. How do I fix this?
[英]gcc - pedantic wont compile, ISO C90 forbids mixed declarations and code How to fix this?
我需要我的程序代码才能有颜色。 但如果我使用-pedantic它就不会编译。 有没有解决的办法? 它的顺便说一下
gcc -pedantic MP1.c -o hahah MP1.c: In function `main': MP1.c:65: warning: ISO C90 forbids mixed declarations and code MP1.c:686:30: warning: (this will be reported only once per input file)
第65行:
int originalAttrs = ConsoleInfo.wAttributes;
将originalAttrs
声明移动到使用它的作用域的顶部。 该错误与使用ConsoleInfo.wAttributes
无关,但与originalAttrs
声明的位置无关。 没有看到整个代码,它可能是这样的:
printf("hello\n"); /* For example. */
int originalAttrs = ConsoleInfo.wAttributes;
修理:
int originalAttrs;
printf("hello\n"); /* For example. */
originalAttrs = ConsoleInfo.wAttributes;
修复代码使其符合C90标准(如hmjd的答案所示),或告诉gcc使用更新版本的标准。
C允许混合声明和以C99标准开头的语句。
如果你使用
gcc -std=c99 -pedantic
要么
gcc -std=c11 -pedantic
它应该工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.