Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
'for' loop initial declaration used outside C99 mode?
Nevada
Unregistered

 
Post: #1
'for' loop initial declaration used outside C99 mode?
So I tried to compile the following code:

Code:
for ( int i = 1; i < exp; i++ )
    val = val + 1;

and it gives me:

'for' loop initial declaration used outside C99 mode.

Uhhh... What exactly is that supposed to mean? Is it because I'm using it inside PrintHello()? (Which is the event handler that is called whenever the window is updated).

Oh, and what's OSStatus? It's placed before the declaration of PrintHello(). Is it just another Carbon thing?
2003.07.30 08:53 PM
Quote this message in a reply
Steven Offline
Senior Member
****

Posts: 720
Joined: Feb 2005
Post: #2
'for' loop initial declaration used outside C99 mode?
Who knows what C99 mode is, but OSStatus is (I think) a typedef'd int. It's used for return codes from system calls.
2003.07.30 09:02 PM
Find all posts by this user Quote this message in a reply
OneSadCookie Offline
Genius Bar
*****

Posts: 2,154
Joined: Feb 2005
Post: #3
'for' loop initial declaration used outside C99 mode?
C99 is a more recent standard of C than the one GCC uses by default.

Declaring the loop counter (in this case i) inside the for loop is only allowed in C++ files unless you tell GCC to use the C99 standard. For C and ObjC, you need to declare i outside the loop.
2003.07.30 09:14 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Patrick
Unregistered

 
Post: #4
'for' loop initial declaration used outside C99 mode?
Code:
for ( int i = 1; i < exp; i++ )
See the "int i = 1"? that's a declaration of the variable i.

The C89 and C94 standards don't support this declaration of i inside a for loop, but C++ and the newest C standard, C99, do.

If you want to have access to this, either make your file a C++ file by renaming it file.cpp, or go into C99 mode by:

PB:
add "std=c99" to "Other C Compiler Settings" under "GCC Compiler Settings" for your target.

straight cc/gcc:
add "std=c99" to your compiler line/makefile/jamfile/whatever.

CodeWarrior:
Check off Enable C99 Extensions, or whatever, in your project settings window.

MPW MrC:
no solution, use C++ instead.

Quote:Oh, and what's OSStatus? It's placed before the declaration of PrintHello(). Is it just another Carbon thing?
If you go into PB and use "Open Quickly..." to open MacTypes.h, you can see a list of many of the common Carbon types.
2003.07.30 09:16 PM
Quote this message in a reply
Nevada
Unregistered

 
Post: #5
'for' loop initial declaration used outside C99 mode?
Ohh.. For some reason I thought I was already programming in C++Tongue. I though the .c was universal and the language was determined at compile time by the compiler settings. Why does Apple use C for their examples? I though C++ was supposed to be industry standard.
2003.07.30 09:29 PM
Quote this message in a reply
Steven Offline
Senior Member
****

Posts: 720
Joined: Feb 2005
Post: #6
'for' loop initial declaration used outside C99 mode?
So is C Tongue
2003.07.30 09:31 PM
Find all posts by this user Quote this message in a reply
OneSadCookie Offline
Genius Bar
*****

Posts: 2,154
Joined: Feb 2005
Post: #7
'for' loop initial declaration used outside C99 mode?
C++ isn't the industry standard because it's a crap language Wink and because of linking issues.

C may not have as many features, but in general it does what it does well, and there are no linking issues.

CodeWarrior allows you to get away with sloppy file endings, but PB/GCC don't. Use the right extension for the language you're writing.
2003.07.30 09:37 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Mars_999
Unregistered

 
Post: #8
'for' loop initial declaration used outside C99 mode?
Quote:Originally posted by OneSadCookie
C++ isn't the industry standard because it's a crap language Wink and because of linking issues.

C may not have as many features, but in general it does what it does well, and there are no linking issues.

CodeWarrior allows you to get away with sloppy file endings, but PB/GCC don't. Use the right extension for the language you're writing.


Hey now thems fighting words! Starting a flame war? Tongue :wow: :lol: Just kidden. Unlike some forums I seen that statement would constitute a huge war. But C++ isn't crap. I myself like C++ better than C mainly do to little things like for() loop variables which C99 took care of. I do like new and delete better than malloc() and free() and cout and cin better than printf() scanf(), but thats all a matter of personal preference.
2003.07.31 01:16 AM
Quote this message in a reply
OneSadCookie Offline
Genius Bar
*****

Posts: 2,154
Joined: Feb 2005
Post: #9
'for' loop initial declaration used outside C99 mode?
Mars, I think you've hung around these forums long enough to know that I'm always up for a flame war about C++, and replying to my posts is probably not a good idea WRT keeping the thread ontopic Tongue

C99 fixes most of my problems with C (like the for loop initial declaration, lack of a bool type, &c).

Malloc is only a couple of macros away from being as friendly as new, and delete is more complicated than free.

I personally like a programming language where what is written means what it says. << and >> mean left and right bit-shift in C and C++ alike. That they may also mean "write to stream" and "read from stream" or whatever else the warped mind of the original programmer decided (cross product anyone?) decided is just a waste of my mental resources. That printing an object to cout could have other side effects without my knowing is beyond absurd.

C++ has a lot of good features. The problem is, they need to be distributed among about ten different languages rather than fighting amongst themselves within one language.
2003.07.31 03:44 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Mars_999
Unregistered

 
Post: #10
'for' loop initial declaration used outside C99 mode?
Quote:Originally posted by OneSadCookie
Mars, I think you've hung around these forums long enough to know that I'm always up for a flame war about C++, and replying to my posts is probably not a good idea WRT keeping the thread ontopic Tongue

C99 fixes most of my problems with C (like the for loop initial declaration, lack of a bool type, &c).

Malloc is only a couple of macros away from being as friendly as new, and delete is more complicated than free.

I personally like a programming language where what is written means what it says. << and >> mean left and right bit-shift in C and C++ alike. That they may also mean "write to stream" and "read from stream" or whatever else the warped mind of the original programmer decided (cross product anyone?) decided is just a waste of my mental resources. That printing an object to cout could have other side effects without my knowing is beyond absurd.

C++ has a lot of good features. The problem is, they need to be distributed among about ten different languages rather than fighting amongst themselves within one language.


I agree with you on the C99 standard. I didn't like the way C was before that I prefered C++'s syntax. I really thought hard about doing away with C++ and just using C as in C99. But I have become so used to using new and delete and classes that its hard to. But I do hate this in C

Code:
//yuck
typedef struct FOO
{
int x;
};

//the most logical way
struct FOO
{
int x;
};

I still am considering just using C but not sure yet. I don't like STL as in vector or the string class. I use C style arrays because they are faster. Maybe for some business programming or app STL is fine but gaming no.
2003.07.31 03:52 AM
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)