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 solut...
[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

Lundin's user avatar

Lundin

187k39 gold badges247 silver badges384 bronze badges

asked Jun 4, 2022 at 6:18

Anon17's user avatar

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.

answered Jun 4, 2022 at 6:18

Anon17's user avatar

Anon17Anon17

1792 silver badges7 bronze badges

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.

answered Jun 9, 2022 at 10:16

Lundin's user avatar

LundinLundin

187k39 gold badges247 silver badges384 bronze badges

0

When writing C language program with DEV-C + +:

[Error] ‘for’ loop initial declarations are only allowed in C99 or C11 mode

Variables declared in the for loop are only allowed in C99 or C11 mode. You need to select C99 in the language standard under tools/compiler option/code generation.

The results are as follows:

Read More:

  • error: ‘for‘ loop initial declarations are only allowed in C99 mode
  • Compiler problem, error: ‘for’ loop initial declarations are only allowed in C99 mode
  • How to Fix error: ‘for’ loop initial declarations are only allowed in C99 mode
  • 【.Net Core】using declarations‘ is not available in C# 7.3. Please use language version 8.0 or greate
  • Fatal error C1853 error occurs when there are mixed .c files in the VS project
  • warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
  • Solutions to error c2143: syntax error: missing ‘;’ before ‘type’ in C + + program compilation
  • C language string processing error warning, c4996, sprintf, predicted, c4996, strcpy, c4996, strcat
  • How to handle when select single is not allowed in loop
  • STOP: c000021a { Fatal System Error } the initial session process or system process terminated …
  • Solution to the problem of no C / C + + option in the new project of eclipse
  • Microsoft Visual C++ 14.0 or greater is required. Get it with “Microsoft C++ Build Tools“
  • Error C2664 in C + + compilation: cannot convert parameter 2 from “const char [5]” to “lpctstr” solution.
  • In R language, for loop or array truncation, the following error occurs only 0’s may be mixed with negative subscripts
  • Solve the problem of error: cannot pass objects of non trivially copyable type ‘STD:: String’ in C / C + +
  • C error C2143 syntax error missing before ‘type’
  • error C2057: expected constant expression (Can the size of an array in C language be defined when the program is running?)
  • Docker encountered a problem 4: yaml: Line 1: mapping values are not allowed in this context
  • A fatal error C1083 occurred when compiling C + + code under. Net: unable to open the include file: “xuhk”_ Jnihelloworld. H “: solution to no such file or directory error.
  • MPI cannot be found in C / C + +

Report

  • I have searched existing issues and this is not a duplicate

Issues and Steps to Reproduce

Building yoga-layout fails when using a Node Docker container, with an error message use option -std=c99, -std=gnu99, -std=c11 or -std=gnu11 to compile your code from error: 'for' loop initial declarations are only allowed in C99 or C11 mode.

Steps to Reproduce:

  1. Install Docker
  2. Download node image: docker pull node
  3. Run interactive container: docker run -it node sh
  4. Try installing yoga-layout in an interactive session: yarn add yoga-layout

This issue should also be present with a standard Debian install, as this is what the Node Docker container is using.

Environment details:

# uname -a
Linux 7726868914e5 4.9.31-moby #1  x86_64 GNU/Linux

# yarn -v
yarn install v0.24.6

# node -v
v8.1.2

Expected Behavior

Describe what you expected would happen.
Should install yoga-layout without errors.

Actual Behavior

Describe what actually happened.

Fails to install.

Full error log is here:

# yarn add yoga-layout
yarn add v0.24.6
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
[1/1] ⠈ yoga-layout: /root/.npm/_logs/2017-07-05T05_25_45_061Z-debug.log
[-/1] ⠈ waiting...
[-/1] ⠈ waiting...
[-/1] ⠈ waiting...
error /node_modules/yoga-layout: Command failed.
Exit code: 1
Command: sh
Arguments: -c npm -- run autogypi && npm -- run build:node
Directory: /node_modules/yoga-layout
Output:
npm info it worked if it ends with ok
npm info using npm@5.0.3
npm info using node@v8.1.2
npm info lifecycle yoga-layout@1.5.0~preautogypi: yoga-layout@1.5.0
npm info lifecycle yoga-layout@1.5.0~autogypi: yoga-layout@1.5.0

> yoga-layout@1.5.0 autogypi /node_modules/yoga-layout
> autogypi

npm info lifecycle yoga-layout@1.5.0~postautogypi: yoga-layout@1.5.0
npm info ok 
npm info it worked if it ends with ok
npm info using npm@5.0.3
npm info using node@v8.1.2
npm info lifecycle yoga-layout@1.5.0~prebuild:node: yoga-layout@1.5.0
npm info lifecycle yoga-layout@1.5.0~build:node: yoga-layout@1.5.0

> yoga-layout@1.5.0 build:node /node_modules/yoga-layout
> npm -- run copy-sources && npm -- run node-gyp configure build

npm info it worked if it ends with ok
npm info using npm@5.0.3
npm info using node@v8.1.2
npm info lifecycle yoga-layout@1.5.0~precopy-sources: yoga-layout@1.5.0
npm info lifecycle yoga-layout@1.5.0~copy-sources: yoga-layout@1.5.0

> yoga-layout@1.5.0 copy-sources /node_modules/yoga-layout
> ! npm -s -- run is-monolithic || (rsync -r --checksum --delete ../yoga/ sources/yoga/)

npm info lifecycle yoga-layout@1.5.0~postcopy-sources: yoga-layout@1.5.0
npm info ok 
npm info it worked if it ends with ok
npm info using npm@5.0.3
npm info using node@v8.1.2
npm info lifecycle yoga-layout@1.5.0~prenode-gyp: yoga-layout@1.5.0
npm info lifecycle yoga-layout@1.5.0~node-gyp: yoga-layout@1.5.0

> yoga-layout@1.5.0 node-gyp /node_modules/yoga-layout
> node-gyp "configure" "build"

gyp info it worked if it ends with ok
gyp info using node-gyp@3.6.2
gyp info using node@8.1.2 | linux | x64
gyp http GET https://nodejs.org/download/release/v8.1.2/node-v8.1.2-headers.tar.gz
gyp http 200 https://nodejs.org/download/release/v8.1.2/node-v8.1.2-headers.tar.gz
gyp http GET https://nodejs.org/download/release/v8.1.2/SHASUMS256.txt
gyp http 200 https://nodejs.org/download/release/v8.1.2/SHASUMS256.txt
gyp info spawn /usr/bin/python2
gyp info spawn args [ '/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/node_modules/yoga-layout/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/usr/local/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/root/.node-gyp/8.1.2/include/node/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/root/.node-gyp/8.1.2',
gyp info spawn args   '-Dnode_gyp_dir=/usr/local/lib/node_modules/npm/node_modules/node-gyp',
gyp info spawn args   '-Dnode_lib_file=/root/.node-gyp/8.1.2/<(target_arch)/node.lib',
gyp info spawn args   '-Dmodule_root_dir=/node_modules/yoga-layout',
gyp info spawn args   '-Dnode_engine=v8',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.' ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
make: Entering directory '/node_modules/yoga-layout/build'
  COPY Release/obj.target/nbind/geni/symbols.txt
  CC(target) Release/obj.target/nbind/sources/yoga/YGNodeList.o
../sources/yoga/YGNodeList.c: In function 'YGNodeListInsert':
../sources/yoga/YGNodeList.c:67:3: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
   for (uint32_t i = list->count; i > index; i--) {
   ^
../sources/yoga/YGNodeList.c:67:3: note: use option -std=c99, -std=gnu99, -std=c11 or -std=gnu11 to compile your code
../sources/yoga/YGNodeList.c: In function 'YGNodeListRemove':
../sources/yoga/YGNodeList.c:79:3: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
   for (uint32_t i = index; i < list->count - 1; i++) {
   ^
../sources/yoga/YGNodeList.c: In function 'YGNodeListDelete':
../sources/yoga/YGNodeList.c:89:3: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
   for (uint32_t i = 0; i < list->count; i++) {
   ^
nbind.target.mk:134: recipe for target 'Release/obj.target/nbind/sources/yoga/YGNodeList.o' failed
make: Leaving directory '/node_modules/yoga-layout/build'
make: *** [Release/obj.target/nbind/sources/yoga/YGNodeList.o] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:258:23)
gyp ERR! stack     at emitTwo (events.js:125:13)
gyp ERR! stack     at ChildProcess.emit (events.js:213:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:197:12)
gyp ERR! System Linux 4.9.31-moby
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "build"
gyp ERR! cwd /node_modules/yoga-layout
gyp ERR! node -v v8.1.2
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok 
npm info lifecycle yoga-layout@1.5.0~node-gyp: Failed to exec node-gyp script
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! yoga-layout@1.5.0 node-gyp: `node-gyp "configure" "build"`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the yoga-layout@1.5.0 node-gyp script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2017-07-05T05_25_45_061Z-debug.log
npm info lifecycle yoga-layout@1.5.0~build:node: Failed to exec build:node script
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! yoga-layout@1.5.0 build:node: `npm -- run copy-sources && npm -- run node-gyp configure build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the yoga-layout@1.5.0 build:node script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2017-07-05T05_25_45_100Z-debug.log

sotoges

0 / 0 / 0

Регистрация: 19.10.2017

Сообщений: 10

1

15.12.2017, 01:14. Показов 16751. Ответов 4

Метки нет (Все метки)


Возникшие проблемы с кодом:

Кликните здесь для просмотра всего текста

main.c||In function ‘print’:|
main.c|5|error: ‘for’ loop initial declarations are only allowed in C99 mode|
main.c|5|note: use option -std=c99 or -std=gnu99 to compile your code|
main.c|7|error: ‘for’ loop initial declarations are only allowed in C99 mode|
main.c|17|error: redefinition of ‘i’|
main.c|5|note: previous definition of ‘i’ was here|
main.c|17|error: ‘for’ loop initial declarations are only allowed in C99 mode|
main.c||In function ‘clear’:|
main.c|23|error: ‘for’ loop initial declarations are only allowed in C99 mode|
main.c||In function ‘main’:|
main.c|42|error: ‘for’ loop initial declarations are only allowed in C99 mode|
||=== Build finished: 6 errors, 0 warnings (0 minutes, 0 seconds) ===|

Код:

C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <stdio.h>
#include <string.h>
void print(char word[], int length)
{
for(int i = 0; i < length; i++)
{
for(int k = length-1; k > i; k--)
{
if(word[k-1] > word[k])
{
char temp = word[k];
word[k] = word[k-1];
word[k-1] = temp;
}
}
}
for(int i = 0; i < length; i++)
printf("%c", word[i]);
}
void clear(char word[])
{
int size = strlen(word);
for(int i = 0; i <= size; i++)
{
word[i] = '';
}
}
int main ()
{
char text [1024], word[20];
puts("Введите текст");
scanf("%s", text);
int end = strlen(text);
int end_index = 0;
int index = 0;
int length = 1;
do
{
clear(word);
int k = 0;
end_index = index + length;
for(int i = index; i < end_index; i++)
{
word[k] = text[i];
k++;
}
index = end_index;
print(word, length);
printf("n");
length++;
} while((end_index + length) <= end);
return 0;
}

__________________
Помощь в написании контрольных, курсовых и дипломных работ, диссертаций здесь



0



sotoges

0 / 0 / 0

Регистрация: 19.10.2017

Сообщений: 10

15.12.2017, 01:32

 [ТС]

2

Возникшие проблемы с кодом:

Кликните здесь для просмотра всего текста

main.c||In function ‘main’:|
main.c|9|error: unknown type name ‘foat’|
main.c|19|error: ‘for’ loop initial declarations are only allowed in C99 mode|
main.c|19|note: use option -std=c99 or -std=gnu99 to compile your code|
main.c|23|warning: format ‘%f’ expects argument of type ‘float *’, but argument 3 has type ‘int *’ [-Wformat]|
main.c|28|error: redefinition of ‘i’|
main.c|19|note: previous definition of ‘i’ was here|
main.c|28|error: ‘for’ loop initial declarations are only allowed in C99 mode|
main.c|33|warning: format ‘%f’ expects argument of type ‘double’, but argument 3 has type ‘int’ [-Wformat]|
main.c|38|error: redefinition of ‘i’|
main.c|28|note: previous definition of ‘i’ was here|
main.c|38|error: ‘for’ loop initial declarations are only allowed in C99 mode|
main.c|46|error: unknown type name ‘foat’|
main.c|47|warning: format ‘%f’ expects argument of type ‘float *’, but argument 2 has type ‘int *’ [-Wformat]|
main.c|48|error: redefinition of ‘i’|
main.c|38|note: previous definition of ‘i’ was here|
main.c|48|error: ‘for’ loop initial declarations are only allowed in C99 mode|
main.c|51|warning: format ‘%f’ expects argument of type ‘double’, but argument 3 has type ‘int’ [-Wformat]|
main.c|53|error: redefinition of ‘i’|
main.c|48|note: previous definition of ‘i’ was here|
main.c|53|error: ‘for’ loop initial declarations are only allowed in C99 mode|
main.c|56|error: ‘for’ loop initial declarations are only allowed in C99 mode|
||=== Build finished: 12 errors, 4 warnings (0 minutes, 0 seconds) ===|

C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <stdio.h>
#include <string.h>
#include <locale.h>
int main()
{
struct toy
{
char name[1024];
foat price;
int lower_limit;
int upper_limit;
};
int amount;
setlocale(LC_ALL,"RUS");
puts("Введите количество игрушек");
scanf("%d", &amount);
 
struct toy toys[amount];
for(int i = 0; i < amount; i++)
{
printf("Введите название, цену и возрастной диапазон для %d игрушкиn", i+1);
scanf("%s%f%d%d", toys[i].name, &toys[i].price,
&toys[i].lower_limit, &toys[i].upper_limit);
}
puts("Ввод информации завершён");
//Поиск самое дорогой игрушки
int max_price = 0;;
for(register int i = 0; i < amount; i++)
{
if (toys[max_price].price < toys[i].price)
max_price = i;
}
printf("Самая дорогоая игрушка - %s стоимостью %.2fn",toys[max_price]. name, toys[max_price].price);
//Подбор игрушек по возрасту
puts("Введите возраст Вашего ребёнка");
int age;
scanf("%d", &age);
for (register int i = 0; i < amount; i++)
{
if ((toys[i].lower_limit < age) && (age < toys[i].upper_limit))
{
printf("Вашему ребёнку подойдёт %sn", toys[i].name);
}
}
puts("Введите ваш бюджет");
foat budget, total_price = 0;
scanf("%f", &budget);
for (register int i = 0; i < amount; i++)
{
if (toys[i].price <= budget)
printf("Вы можете купить %s на ваши деньги. У вас как раз останется %.2f на чашечку кофеn", toys[i].name, budget - toys[i].price);
}
for (register int i = 0; i < amount; i++)
{
total_price = toys[i].price;
for (register int k = 0; k < amount; k++)
{
total_price += toys[k].price;
if (total_price <= budget)
{
printf("Вы можете купить на ваши деньги комплект из %s и %sn", toys[i].name, toys[k].name);
}
}
}
return 0;
}



0



3532 / 2196 / 401

Регистрация: 09.09.2017

Сообщений: 9,050

15.12.2017, 08:48

3

Цитата
Сообщение от sotoges
Посмотреть сообщение

main.c|9|error: unknown type name ‘foat’|

Возможно, имелся в виду float?

Цитата
Сообщение от sotoges
Посмотреть сообщение

main.c|19|error: ‘for’ loop initial declarations are only allowed in C99 mode|

Либо включите совместимость с С99 или выше (в gcc это -std=c99), собственно, в следующей строке вам это и написали, либо вынесите объявление переменной в начало функции.
Большая часть остальных сообщений — следствие этих двух ошибок



0



14 / 14 / 0

Регистрация: 01.12.2017

Сообщений: 577

15.12.2017, 12:51

4

int i объяви в начале функции. а в for (i=0;i<=size; i++)



0



LaFayette

48 / 48 / 57

Регистрация: 25.11.2015

Сообщений: 140

15.12.2017, 13:11

5

Цитата
Сообщение от sotoges
Посмотреть сообщение

main.c||In function ‘print’:|
main.c|5|error: ‘for’ loop initial declarations are only allowed in C99 mode|
main.c|5|note: use option -std=c99 or -std=gnu99 to compile your code|

Инициализация в цикле for доступна начиная со стандарта С99. Для использования стандарта во время компиляции нужно добавить опцию -std=c99.

Например

Bash
1
gcc hello.c -std=c99 -o hello.exe



0



Rowlandski

#@>=11

  • Total Posts : 253
  • Reward points : 0
  • Joined: 2008/08/28 02:09:14
  • Location: UK — Herts
  • Status: offline

I’ve just pulled in sum code i wrote a while back and i’m getting the following error:

 error: ‘for’ loop initial declarations are only allowed in C99 mode

 How do I allow «C99 mode»?

 long power (long number, long order)
{
    long result = number;
    for (unsigned int n = 0; n < (order - 1); n++)
    {
        result = result * number;
    }

    if (order == 0)
    {
        result = 1;
    }
    return (result);
}

 Thanks.

post edited by Rowlandski — 2017/06/02 04:35:41

qhb

Superb Member

  • Total Posts : 9999
  • Reward points : 0
  • Joined: 2016/06/05 14:55:32
  • Location: One step ahead…
  • Status: offline

Re: error: ‘for’ loop initial declarations are only allowed in C99 mode


2017/06/02 03:15:38

(permalink)

XC16 is a «C89» compiler, with a few C99 extensions.
I don’t think there is a C99 mode in XC16 at all. That’s an awkward way of saying «that is a C99 feature that I don’t support at all».

du00000001

Just Some Member

  • Total Posts : 5302
  • Reward points : 0
  • Joined: 2016/05/03 13:52:42
  • Location: Germany
  • Status: offline

Re: error: ‘for’ loop initial declarations are only allowed in C99 mode


2017/06/02 03:15:47

(permalink)

project properties | compiler options
Cannot recall the exact name of the option but clicking a bit should result in success.

CinziaG

die fucking humans

  • Total Posts : 3183
  • Reward points : 0
  • Joined: 2016/12/07 14:20:36
  • Location: Wien
  • Status: offline

Re: error: ‘for’ loop initial declarations are only allowed in C99 mode


2017/06/02 04:01:09

(permalink)

I actually never felt the need for that feature. «localizing variables», yeah, oh well…

qhb

Superb Member

  • Total Posts : 9999
  • Reward points : 0
  • Joined: 2016/06/05 14:55:32
  • Location: One step ahead…
  • Status: offline

Re: error: ‘for’ loop initial declarations are only allowed in C99 mode


2017/06/02 04:06:57

(permalink)

du00000001
project properties | compiler options
Cannot recall the exact name of the option but clicking a bit should result in success.

Are you sure? There’s no mention of it in the latest XC16 User Guide.

Rowlandski

#@>=11

  • Total Posts : 253
  • Reward points : 0
  • Joined: 2008/08/28 02:09:14
  • Location: UK — Herts
  • Status: offline

Re: error: ‘for’ loop initial declarations are only allowed in C99 mode


2017/06/02 04:15:52

(permalink)

qhb

du00000001
project properties | compiler options
Cannot recall the exact name of the option but clicking a bit should result in success.

Are you sure? There’s no mention of it in the latest XC16 User Guide.

True, I couldn’t find it either.

rodims

Super Member

  • Total Posts : 1558
  • Reward points : 0
  • Joined: 2009/02/10 11:08:59
  • Location: 51.9627, 7.6262
  • Status: offline

Re: error: ‘for’ loop initial declarations are only allowed in C99 mode


2017/06/02 04:25:55

(permalink)

Ahem, why did’nt you read the next line the compiler outputs ?  (XC16 v1.31)

 ../main.c:1368:2: error: ‘for’ loop initial declarations are only allowed in C99 mode
../main.c:1368:2: note: use option -std=c99 or -std=gnu99 to compile your code

 Adding this option works as expected.
However this changes more than this, i.e. you then will get different warnings for other stuff etc …

qhb

Superb Member

  • Total Posts : 9999
  • Reward points : 0
  • Joined: 2016/06/05 14:55:32
  • Location: One step ahead…
  • Status: offline

Re: error: ‘for’ loop initial declarations are only allowed in C99 mode


2017/06/02 04:29:42

(permalink)

Must be a GCC option that’s not officially supported.

Rowlandski

#@>=11

  • Total Posts : 253
  • Reward points : 0
  • Joined: 2008/08/28 02:09:14
  • Location: UK — Herts
  • Status: offline

Re: error: ‘for’ loop initial declarations are only allowed in C99 mode


2017/06/02 04:35:12

(permalink)

Sorry, missed the info.

 using:

 -std=gnu99

 Works

Gort2015

Klaatu Barada Nikto

  • Total Posts : 6043
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline

Re: error: ‘for’ loop initial declarations are only allowed in C99 mode


2017/06/02 06:20:55

(permalink)

Careful when setting, «additional options», due to mplab x bugs these can get deleted.

 It has happened to me a lot.  You have to paste them back in, annoying when you have 10 projects open.

mlp

boots too small

  • Total Posts : 1023
  • Reward points : 0
  • Joined: 2012/09/10 15:12:07
  • Location: previously Microchip XC8 team
  • Status: offline

Re: error: ‘for’ loop initial declarations are only allowed in C99 mode


2017/06/02 08:21:03

(permalink)

rowlandwhiffin
-std=gnu99

 Be aware that this causes the language the compiler supports to be «GNU C 99», which is different from ISO Standard C 99.

Mark (this opinion available for hire)

du00000001

Just Some Member

  • Total Posts : 5302
  • Reward points : 0
  • Joined: 2016/05/03 13:52:42
  • Location: Germany
  • Status: offline

Re: error: ‘for’ loop initial declarations are only allowed in C99 mode


2017/06/02 08:39:04

(permalink)

You’re prone to die — one or another way.

Silvestre

New Member

  • Total Posts : 26
  • Reward points : 0
  • Joined: 2017/05/09 20:15:18
  • Location: 0
  • Status: offline

Re: error: ‘for’ loop initial declarations are only allowed in C99 mode


2017/06/04 05:10:27

(permalink)

Hi, I use Matlab/Simulink(R) coder for code generation for dsPIC, PIC18 and ARM Cortex M4 (using Keil).
I always put the additional option: -std=gnu99, and the code work excellent. 
With this set, implement PIDs, Transfer functions, State flow, Fuzzy Logic, Kalman filter, etc. etc. is too easy.
With this additional option, you can use: for (uint8_t i = 0; i<10; i++), for example.

 Although it is not stated in the literature of Microchip, it is always good to work with the gnu99 standard since you have access to shared libraries, for example using Matlab / Simulink coder, one gets to have the power of simulink inside the dsPIC. And for example in ARM, it is possible to use the CMSIS libraries in the generated code. GNU99 also allows programming using the MISRA-C 2012 guidelines for critical systems.

 I recommend using the new standards for numerical formats, uint8_t instead of unsigned char, int16_t instead of int, etc.


#include <stdint.h> /* Includes uint16_t definition */
#include <stdbool.h> /* Includes true/false definition */

 Regards!

DLChambers

Starting Member

  • Total Posts : 39
  • Reward points : 0
  • Joined: 2003/11/07 12:36:49
  • Status: offline

Re: error: ‘for’ loop initial declarations are only allowed in C99 mode


2022/03/11 12:03:22

(permalink)

Project Properties > Conf > XC16 > XC16 (Global Options) > Additional Options «-std=gnu99»

I wish I’d paid attention in my high school typing class…

crosland

Super Member

  • Total Posts : 2926
  • Reward points : 0
  • Joined: 2005/05/10 10:55:05
  • Location: Warks, UK
  • Status: offline

Re: error: ‘for’ loop initial declarations are only allowed in C99 mode


2022/03/11 13:34:54

(permalink)

5 years on, I rather think the OP has moved on.

Topic: Problem compiling «for loop» with codeblocks compiler.  (Read 25633 times)

Hi friends,

I am using GNU GCC Compiler

OS: win7 32bit

/* Program 4.2 Drawing a box */
#include <stdio.h>
int main(void)
{
printf(«n**************»); /* Draw the top of the box */
for(int count = 1 ; count <= 8 ; ++count)
printf(«n* *»); /* Draw the sides of the box */
printf(«n**************n»); /* Draw the bottom of the box */
return 0;

}

when i try to compile the code i got fallowing error.

C48.c|6|error: ‘for’ loop initial declarations are only allowed in C99 mode|
C48.c|6|note: use option -std=c99 or -std=gnu99 to compile your code|

If anybody know how to change it to c99mode please help me.

Thanks & Regards,

Deva

Hi, I changed to -std=c99 mode is this way correct ?

Please see picture
Untitled.png:

Hi friends,

My problem solved. many of them adviced me to change settings to -std=c99 But its not worked because my compiler is GNU GCC Compiler.

Here is see how the problem is fixed.

In the Compiler and Debugger settings. Compiler settings tab — Other Options. I added there -std=gnu99

So Problem solved.

Friends thanks very much for your advices & time.

Thanks & Regards,

Deva

« Last Edit: November 10, 2011, 04:24:57 pm by deva »


Logged


zabzonk

Go to the Project menu, then Build Options…, then Compiler Settings|Other options tab, then enter -std=c99 and hit OK.


Logged


Hi,

Thanks for your reply. In the projecet menu build options is disable I mean its not highlited. How can we enable it?.


Logged


zabzonk

CB is project based. Before you write any code, create a project from Create New Project on the CB startup screen, and select Console Application — the Build Options will be enabled after you create a project.


Logged


CB is project based. Before you write any code, create a project from Create New Project on the CB startup screen, and select Console Application — the Build Options will be enabled after you create a project.

Wrong, C::B supports single file compilation, too.
For the compilation it uses the default compiler,
so you can set the option in the settings,
but this is not a good practice in the long run.
No, debugging is supported in single file mode.


Logged

(most of the time I ignore long posts)
[strangers don’t send me private messages, I’ll ignore them; post a topic in the forum, but first read the rules!]


zabzonk

> Wrong, C::B supports single file compilation, too.

What is «wrong»? Do you deny that that CB is project based? Can you use Build Options without a project, which is what the OP needs to do, without using what you yourself say is «bad practice»? No, you can’t.

« Last Edit: November 10, 2011, 10:34:52 am by Neil Butterworth »


Logged


I gues you use a *.c file.
The easiest way would be to rename it to *.cpp, so it is compiled with the c++-compiler.


Logged


zabzonk

> The easiest way would be to rename it to *.cpp, so it is compiled with the c++-compiler.

But then he runs into problems if he uses C99 features not supported by C++.


Logged


IMO, Jens is correct. You problem consists in «for( int count = 1 ; …» This kind of declaring local variables in a loop statement (or other statements) is usual in C++ for a long time. Perhaps, a norm is it starting from C99. GCC is over strict sometimes …

(1) Either switch to C++ by renaming 48.c to 48.cpp or selecting C++ compiler explicitely.
(2) Or declare «int count» like a normal variable declaration at the beginning of main().

When you opt for (1) you can get a similar paranoid message. When you opt for (2), you should pass even with a  C compiler.


Logged


zabzonk

@Radek. It is perfectly legal (and good)  C99  code, and the OP obviously wants to use C99. Telling him to switch to C++, a completely different language, is IMHO very bad advice.


Logged


Hi friends,

Non of the your advices working. Is there any way still fix the problem. Actually I am newbie to programming. I am just teaching my self from book «C-FromNoviceToProfessional4thEd(2006)» by Ivor Horton,  Apress

I tried to compile the same code in Borland Turboo C++ compiler. Its work fine.

But i really like to use CB because its highlight the syntax in colors. So, code looks clean & good.

Any help greately appreciated.

Thanks & Regards,

Deva


Logged


zabzonk

@Deva The code will definitely compile if you rename the file to a  .cpp extension, but if you are trying to learn C rather than C++ this is not the best solution, as it means things that are mistakes in C but not in C++ will not be caught. My solution of creating a console application project and supplying the -std=c99 option should definitely work — it did when I tried it myself — and is the correct way to go if you want to learn C99. Did you actually try it?


Logged


The following does not work?

#include <stdio.h>

int main(void)
{
  int count;

  printf("n**************");       

  for( count = 1 ; count <= 8 ; ++count ) printf("n* *");

  printf("n**************n");

  return 0;
}


Logged


Понравилась статья? Поделить с друзьями:

Читайте также:

  • Error for loop initial declaration used outside c99 mode
  • Error flow is broken director cannot populate world
  • Error code 291 standoff 2 что значит
  • Error floating point exception ansys
  • Error code 29004 this list name has been used

  • 0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии