This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: about the 'for' statement
- To: Wang Yong <wung_y@263.net>
- Subject: Re: about the 'for' statement
- From: Branko Cibej <branko.cibej@hermes.si>
- Date: Mon, 16 Aug 1999 10:15:39 +0200
- CC: gcc maillist <gcc@gcc.gnu.org>
- Organization: HERMES SoftLab
- References: <001001bee7b5$4c2da830$0601a8c0@honey.cs.tsinghua.edu.cn>
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