> I think this might be a silly quiestion, but I am curious.
>
> When I ported my mod over to Linux, I had to change a bunch of counter
> loops:
>
> for ( int i = 1; i <= gpGlobals->maxClients; i++ )
>
>
> to this style
>
> int i;
>
> for ( i = 1; i <= gpGlobals->maxClients; i++ )
>
>
> For ansi compliance. The question is this, why did not all of the loops
> have to change? and would there be a problem with the value ever being
> passed to the wrong counter?
>
> I mean I know it has something to do with scope, but this just seems odd
> that not all loops gave errors??
The problem isn't that...
for (int x = 0; x < MAX; x++)
...is a problem for the Linux gcc compiler (it's perfectly fine by itself).
The problem is that in ANSI C++, the variable only has scope within the
"for" loop. The Microsoft C++ compiler let's you do this...
for (int x = 0; x < MAX; x++)
{
// stuff here
}
if (x == MAX) // did the loop complete?
// stuff here
...in ANSI C++ the 'x' within the "for" loop does not exist outside of the
loop and thus, in the "if" statement below it, 'x' is an undeclared variable
(as it should be).
The Microsoft C++ compiler just has not kept updated to adhere to the latest
ANSI standards, thus making the porting of code from Windows to Linux a
little bit more troublesome.
Jeffrey "botman" Broome
_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders