简体   繁体   中英

Error - 'for' loop initial declarations are only allowed in C99 or C11 mode

[Error] 'for' loop initial declarations are only allowed in C99 or C11 mode
[Note] use option -std=c99, -std=gnu99, -std=c11 or -std=gnu11 to compile your code

I'm giving the above problem's solution, note that I'm using DevC++ code editor here

I'm giving the above problem's solution, note that I'm using DevC++ code editor here

The above error can be solved by following the steps given below ---

Step 1 - Go to 'Tools'.

Step 2 - Then Click on 'Compiler Options'.

Step 3 - Find 'Settings' tab there.

Step 4 - Under settings tab you'll find 'Code Generation' sub tab.

Step 5 - Now find 'Language Standard(-std)' option.

Step 6 - Click on downward arrow and then select there 'ISO C99' option.

Step 7 - Now click on OK and you're good to go.

The problem is that the antique tool DevC++ uses a very old version of gcc. Meaning it is unsuitable for study/learning purposes.

All versions prior gcc 5.0.0 (released some ~7 years ago) used -std=gnu90 as the default setting. Modern versions of gcc use -std=gnu11 (up to version 10) or -std=gnu17 (from 10.2.x), which is the lax mode of the modern C11/C17 versions of the standard, also including various GNU C and POSIX extensions.

Unless your major is Software Archaeology, the recommended solution is to update to a better IDE. DevC++ is as far as I know not maintained since forever and it also uses an older branch of the MinGW compiler project (32 bit) also not maintained since forever.

One IDE alternative for Windows is Codeblocks , which is free and beginner-friendly, but still advanced enough to also be used for professional purposes. It comes with a fairly recent gcc/mingw version as default.

If you want the latest version of gcc/mingw64 for Windows, you can download & install it separately as described here: How to install MinGW-w64 and MSYS2? I recommend to download the compiled binaries from https://winlibs.com/ since the official Sourceforge link currently contains corrupt binaries.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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