dumb q moving to gcc - c99 mode

M

MikeyD

Just switched to using gcc on my windows 98 pc. Programs were compiling fine
on a propriety compiler. Now, though, it gives me an error message for a for
loop, "line xx: use of header-defined for loop outside of c99 mode". What is
this?
 
P

Pieter Droogendijk

Just switched to using gcc on my windows 98 pc. Programs were compiling fine
on a propriety compiler. Now, though, it gives me an error message for a for
loop, "line xx: use of header-defined for loop outside of c99 mode". What is
this?

Post the smallest compilable snippet triggering this error.
 
M

Mark A. Odell

Just switched to using gcc on my windows 98 pc. Programs were compiling
fine on a propriety compiler. Now, though, it gives me an error message
for a for loop, "line xx: use of header-defined for loop outside of c99
mode". What is this?

Not sure, I can't read your mind. Show us a very small example of the
problem code.
 
M

Mac

Just switched to using gcc on my windows 98 pc. Programs were compiling fine
on a propriety compiler. Now, though, it gives me an error message for a for
loop, "line xx: use of header-defined for loop outside of c99 mode". What is
this?


I don't know exactly what the message means, but there must be some way to
invoke gcc so that it is more permissive. Maybe check out the
documentation for gcc. Do a "man gcc" or a "gcc --help".

From the context, I am pretty sure that "c99 mode" means a mode where gcc
allows some of the features from the c standard as ratified in 1999 (as
opposed to the previous standard which is usually called c89).

So, since it sounds like it has something to do with c99, try searching
through the documentation for "c99." I'm sure you'll find a solution. ;-)


Mac
--
 
S

Simon Biber

MikeyD said:
Just switched to using gcc on my windows 98 pc. Programs were compiling fine
on a propriety compiler. Now, though, it gives me an error message for a for
loop, "line xx: use of header-defined for loop outside of c99 mode". What is
this?

I don't know that error message specifically. However it's probably similar to:

int main(void)
{
for(int i = 0; i < 10; i++);
return 0;
}

C:\prog\c>gcc mikeyd.c
mikeyd.c: In function `main':
mikeyd.c:3: `for' loop initial declaration used outside C99 mode

You can fix this by just adding -std=c99 to the command line.

Or, if you want the code to function properly on older compilers, you
will need to move all the declarations out of the for loops whenever
this occurs.
 
M

MikeyD

Pieter Droogendijk said:
Post the smallest compilable snippet triggering this error.
#include <stdio.h>
int main(void){
for(int i=1;i<10;i++)
printf("%d",i);
return 0;
}
I may have mixed up error messages, since I'm now getting "test.c:3: error:
'for' loop initial declaration used outside c99 mode"
 
M

Mac

I don't know that error message specifically. However it's probably
similar to:

int main(void)
{
for(int i = 0; i < 10; i++);
return 0;
}

C:\prog\c>gcc mikeyd.c
mikeyd.c: In function `main':
mikeyd.c:3: `for' loop initial declaration used outside C99 mode

You can fix this by just adding -std=c99 to the command line.

And making sure you don't also use -ansi, as this seems to override
-std=c99.

Mac
--
 
J

John Tsiombikas (Nuclear / the Lab)

MikeyD said:
#include <stdio.h>
int main(void){
for(int i=1;i<10;i++)
printf("%d",i);
return 0;
}
I may have mixed up error messages, since I'm now getting "test.c:3: error:
'for' loop initial declaration used outside c99 mode"

The problem is that in C you can't declare a variable at the initialization part
of the for-loop as you can in C++ for example. That's changed though in C99,
that's why the compiler tells you that either your code is wrong, or you forgot
to tell it you are writing C99.

-- Nuclear / the Lab --
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top