iDevGames Forums
xcode flag for for-loop scoping - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Tools & Technology (/forum-10.html)
+--- Thread: xcode flag for for-loop scoping (/thread-3172.html)



xcode flag for for-loop scoping - Rasterman - Jul 18, 2007 09:20 PM

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.


xcode flag for for-loop scoping - Skorche - Jul 18, 2007 11:36 PM

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.


xcode flag for for-loop scoping - OneSadCookie - Jul 18, 2007 11:56 PM

GCC always scopes for-loops correctly. There is no "-stupid-msvc6-compat" flag or anything. You'll have to fix the code.


xcode flag for for-loop scoping - Rasterman - Jul 19, 2007 06: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.


xcode flag for for-loop scoping - Hog - Jul 19, 2007 05:25 PM

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).


xcode flag for for-loop scoping - OneSadCookie - Jul 19, 2007 10:51 PM

Yes, Whatever the next version after 6 was called does it properly.


xcode flag for for-loop scoping - operator - Mar 16, 2008 05:56 PM

Use this to fix MSC6:

#define for if(0) { } else for


xcode flag for for-loop scoping - OneSadCookie - Mar 16, 2008 06:14 PM

much less confusing and equally working:
Code:
#define for if (1) for



xcode flag for for-loop scoping - mattz - Mar 17, 2008 04: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


xcode flag for for-loop scoping - ThemsAllTook - Mar 17, 2008 05:29 AM

Yet another reason to always use braces.


xcode flag for for-loop scoping - wyrmmage - Mar 17, 2008 06:19 AM

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/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


xcode flag for for-loop scoping - Josh - Mar 17, 2008 08:09 AM

The real question is why the heck anyone would rely on that kind of bad programming practice.