xcode flag for for-loop scoping
I know this question must have been answered already, but I tried searching google and the forums for it and couldn't find anything.
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
(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.
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
(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.
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.
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.
Code:
-std=gnu99GNU99 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.
GCC always scopes for-loops correctly. There is no "-stupid-msvc6-compat" flag or anything. You'll have to fix the code.
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.
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).
Yes, Whatever the next version after 6 was called does it properly.
Use this to fix MSC6:
#define for if(0) { } else for
#define for if(0) { } else for
much less confusing and equally working:
Code:
#define for if (1) for
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
Yet another reason to always use braces.
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...

-wyrmmage
Worlds at War (Current Project) - http://www.awkward-games.com/forum/
The real question is why the heck anyone would rely on that kind of bad programming practice.

