Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: for loop localisation bug?(C For Loop)

by MADuran (Beadle)
on Dec 29, 2003 at 21:24 UTC ( #317557=note: print w/ replies, xml ) Need Help??


in reply to Re: Re: Re: Re: Re: for loop localisation bug?
in thread for loop localisation bug?

ANSI/ISO/IEC Standard 9899:1999 (C99 Standard) (Link to ANSI's Store) allows allocation of the identifer in the for statement and scopes the identifer to the loop only

This code is now legal in C99 compilers (which to my knowledge there are not very many)

for(int i=0; i < 100; i++){ /*do some thing with i */ printf("this is i: %d", i); }

and it is lexically the same as:

{ int i; for(i=0; i < 100; i++){ /*do something here with i */ printf("this is i: %d", i); } }
**This code is Not Tested (even for correctness)**
Note that the second code sinpet is blocked, limiting the scope of i in the for statement. References are the Swedish Instute of Computer Science (which posted the C99 Standard here (a PDF) if this is not a legal posting please remove link)
6.8.5.3 is the paragraph dealing with the FOR statement

And this overview of C99

This does NOT invalidate your argument about pre c99 compilers or non-complying compilers. And if you declare your iterator loop varable before the for loop it will work the same as it did previouly. I point this out because I think that this is what these other fine Monks must be thinking of.

MADuran who must now find a spiffy sig.


Comment on Re: for loop localisation bug?(C For Loop)
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://317557]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (14)
As of 2014-10-01 12:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (18 votes), past polls