Re: Error: 'for' loop initial declaration used outside c99 mode
- From: rlb@xxxxxxxxxxxxxxxxxxxxxx (Richard Bos)
- Date: Fri, 03 Nov 2006 09:06:07 GMT
james of tucson <jmcgill@[go_ahead_and_spam_me].arizona.edu> wrote:
Pedro Pinto wrote:
When compiling my program i got this error:
Error: 'for' loop initial declaration used outside c99 mode
What is it and how can i solve it?
You're coming to C from a Java background, aren't you?
This is illegal in most C dialects; it is a legal C++ declaration, and
so may be accepted if you are compiling C with a C++ compiler:
Unless you severely hobble your C, that is not generally possible.
for( int k=0; k<10; k++){}
A better solution is to _read_ the error message. It clearly (and
correctly) states that this construct is not legal ISO C outside C99;
the obvious (and also correct) conclusion is that it _is_ legal ISO C99.
There are two reasonable solutions to this problem:
- stick with C89 (or even pre-ANSI C), and move the declaration outside
the for loop, to the beginning of any available block (probably the
function block);
- read the documentation of your compiler, which evidently does have a
C99 mode, and use that mode.
Richard
.
- Follow-Ups:
- Re: Error: 'for' loop initial declaration used outside c99 mode
- From: Ian Collins
- Re: Error: 'for' loop initial declaration used outside c99 mode
- References:
- Error: 'for' loop initial declaration used outside c99 mode
- From: Pedro Pinto
- Re: Error: 'for' loop initial declaration used outside c99 mode
- From: james of tucson
- Error: 'for' loop initial declaration used outside c99 mode
- Prev by Date: Re: bit fields pointers?
- Next by Date: Re: Cannot return values of char variable
- Previous by thread: Re: Error: 'for' loop initial declaration used outside c99 mode
- Next by thread: Re: Error: 'for' loop initial declaration used outside c99 mode
- Index(es):
Relevant Pages
|
|