Re: [patch] Bug #459

Todd Warner (
Fri, 18 Jun 1999 14:54:18 -0400

Shaw Terwilliger wrote:

> Aaron Lehmann wrote:
> >
> > I summerized the description of the metrowerks problem and added it to the
> > programmer guidelines. here's the patch:
> Again, I don't claim to be the ANSI C++ expert, but the patch says:
> For example, this is perfectly legal C++:
> for (int i=0; i > 10; i++) {
> printf("i is %d \n", i);
> }
> printf("I is now %d \n", i);
> ... but I really don't think it is. :) The ANSI C++ drafts I could
> find (I should buy the ANSI/ISO standard to stick on my bookshelf)

A for loop is a scoping block. Therefore, you are correct, i is scoped to the
for loop only. Old Borland (I don't know about the current one) and Visual
C++ (the current one even) both screw this up. Egcs scopes it properly.

> say i should not be visible outside the loop. In short, if you want
> to use it, declare it before the for(). By this it seems MetroWorks
> C++ is very ANSI/ISO compliant. EGCS also tells you not to do this:

I only confirm this because I want to inform people that a number of compilers
overlook this error. In a word (phrase?): be careful!

-Todd Warner

This archive was generated by hypermail 1.03b2.