Topic: for statement scope question (cfront bug?)


Author: rfg@netcom.com (Ronald F. Guilmette)
Date: Fri, 31 Dec 1993 09:46:23 GMT
Raw View
In article <2f72op$gfv@tornews.torolab.ibm.com> thomson@cppfs.torolab.ibm.com (Brian Thomson) writes:
>In article <2f6sbnINN5gf@sbusol.rz.uni-sb.de>,
>Stefan <stefan@mpi-sb.mpg.de> wrote:
>>main()
>>{
>>    for(int x=0; x<10; x++)
>>      for(int y=0; y<10; y++)
>>        for(int x=0; x<10; x++);
>> }
>>
>>cfront says: error: two declarations of x
>
>Cfront is correct here, a "for" statement does not begin a new scope.
>
>--
>Brian Thomson   THOMSON at TOROLAB
>OS/2 C++ Development  thomson@vnet.ibm.com

Correct, but I was led to believe that (nowadays) the body of a structured
statement *is* in fact a new scope.

If true, that would mean that the above code is equivalent to:

 for(int x=0; x<10; x++)
   {
     for(int y=0; y<10; y++)
       {
  for(int x=0; x<10; x++);
       }
   }

which is valid code.

--

-- Ronald F. Guilmette, Sunnyvale, California -------------------------------
------ domain address: rfg@netcom.com ---------------------------------------
------ uucp address: ...!uunet!netcom.com!rfg -------------------------------