This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: about the 'for' statement


Wang Yong wrote:

> Hi, all
>   in gcc,

This has nothing to do with gcc. This is a question about the
C (or C++) language.

> how 'for' statement is translated?
>
>   for example:
>
>   for (i=1;i++;i<10){
>       //some statement here
>   }
>
>   If this for statement will be translated to something like this :
>
>   i=1;
> l1:
>   if (i<10){
>         //some statements here
>         i++;
>         goto l1;
>   }
>
> or
>
>   i=1;
> l1:
>   i++;
>   if (i<10){
>         //some statements here
>         goto l1;
>   }

Neither, of course :-)  From your example, you'll get this:

       i=1;
     l1:
       if (i++)
         {
           /*some statements here*/
           i<10;
           goto l1;
         }

On the other hand, if you put the condition in the right place:

     for (i=1; i<10; i++)
       {
         /*some statements here*/
       }

you'll get your first expansion.

    Brane

--
Branko Čibej                 <branko.cibej@hermes.si>
HERMES SoftLab, Litijska 51, 1000 Ljubljana, Slovenia
voice: (+386 61) 186 53 49   fax: (+386 61) 186 52 70



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]