View Full Version : xcode flag for for-loop scoping
Rasterman
2007.07.19, 12:20 AM
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.
Skorche
2007.07.19, 02:36 AM
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.
-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.
OneSadCookie
2007.07.19, 02:56 AM
GCC always scopes for-loops correctly. There is no "-stupid-msvc6-compat" flag or anything. You'll have to fix the code.
Rasterman
2007.07.19, 09:52 AM
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).
OneSadCookie
2007.07.20, 01:51 AM
Yes, Whatever the next version after 6 was called does it properly.
operator
2008.03.16, 08:56 PM
Use this to fix MSC6:
#define for if(0) { } else for
OneSadCookie
2008.03.16, 09:14 PM
much less confusing and equally working: #define for if (1) for
mattz
2008.03.17, 07:02 AM
Actually, the else is good because it prevents you from inadvertently closing an earlier if block -- see http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.4
ThemsAllTook
2008.03.17, 08:29 AM
Yet another reason to always use braces.
wyrmmage
2008.03.17, 09:19 AM
Actually, the else is good because it prevents you from inadvertently closing an earlier if block -- see http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#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
The real question is why the heck anyone would rely on that kind of bad programming practice.
vBulletin® v3.6.8, Copyright ©2000-2008, Jelsoft Enterprises Ltd.