xcode flag for for-loop scoping

Member
Posts: 81
Joined: 2007.07
Post: #1
I know this question must have been answered already, but I tried searching google and the forums for it and couldn't find anything. Blush I am porting a game and need to turn off the strict ANSI scoping in xcode, what is the compiler flag or option to do this and how do I do it?

For example:
for(int i=0; i<10; i++) count++;
for(i=0; i<10; i++) count++;

Compiles fine in MSVC6 but xcode shows a variable binding error Cry (which I know is correct ANSI C and MSVC is wrong), but all of my code is written this way and frankly it has always worked great for me, so I need to know how to compile this way, thanks for your help.
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #2
You weren't exactly clear. What you want is to be able to declare the int in the for loop? You'll need to enable C99 mode to do that.

Code:
-std=gnu99

GNU99 isn't exactly C99, but it's quite close.

EDIT: I remember someone talking about there being an error that caused MSVC to leak the variable past the for-loop's scope. If that's the problem, then I think you're probably out of luck.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #3
GCC always scopes for-loops correctly. There is no "-stupid-msvc6-compat" flag or anything. You'll have to fix the code.
Quote this message in a reply
Member
Posts: 81
Joined: 2007.07
Post: #4
Yeah I was talking about leaking the scope. After compiling out more errors though it looks like it won't be too bad to fix them all.
Quote this message in a reply
Hog
Member
Posts: 151
Joined: 2002.09
Post: #5
Leaking from the scope is clearly a bug in MSVC6 not a feature. You shouldn't be relying on bugs as they may get fixed sooner or later (though I have no idea if that one ever got fixed for later versions).
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #6
Yes, Whatever the next version after 6 was called does it properly.
Quote this message in a reply
Apprentice
Posts: 11
Joined: 2006.08
Post: #7
Use this to fix MSC6:

#define for if(0) { } else for
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #8
much less confusing and equally working:
Code:
#define for if (1) for
Quote this message in a reply
Member
Posts: 45
Joined: 2006.07
Post: #9
Actually, the else is good because it prevents you from inadvertently closing an earlier if block -- see http://www.parashift.com/c++-faq-lite/mi...l#faq-39.4
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #10
Yet another reason to always use braces.
Quote this message in a reply
Moderator
Posts: 371
Joined: 2006.08
Post: #11
mattz Wrote:Actually, the else is good because it prevents you from inadvertently closing an earlier if block -- see http://www.parashift.com/c++-faq-lite/mi...l#faq-39.4

quite true.

On the subject we've been talking about, I'm pretty sure that XCode 2.* includes a flag that will, in fact, let your for variables leak. I don't recommend using it, obviously, but I do believe it is an option....I'll have to go and check to make sure, though... Sneaky
-wyrmmage

Worlds at War (Current Project) - http://www.awkward-games.com/forum/
Quote this message in a reply
Moderator
Posts: 608
Joined: 2002.04
Post: #12
The real question is why the heck anyone would rely on that kind of bad programming practice.
Quote this message in a reply
Post Reply