* Re: about the 'for' statement
@ 1999-08-16 10:54 R. Kelley Cook
1999-08-16 11:33 ` Per Bothner
1999-08-31 23:20 ` R. Kelley Cook
0 siblings, 2 replies; 8+ messages in thread
From: R. Kelley Cook @ 1999-08-16 10:54 UTC (permalink / raw)
To: egcs
On 16 Aug 1999 09:03:09 +0200, Wang Yong wrote:
>Hi, all
> in gcc, how 'for' statement is translated?
>
> for example:
>
> for (i=1;i++;i<10){
> //some statement here
> }
>
Strange question, you already wrote enough to check the answer yourself.
All you had to do was change your code to be ...
for (i=1;i++;i<10){
printf("%d",i); //some statement here
}
and you would have realized the answer.
> If this for statement will be translated to something like this :
>
> i=1;
>l1:
> if (i<10){
> //some statements here
> i++;
> goto l1;
> }
>
yes
>or
>
> i=1;
>l1:
> i++;
> if (i<10){
> //some statements here
> goto l1;
> }
no
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: about the 'for' statement
1999-08-16 10:54 about the 'for' statement R. Kelley Cook
@ 1999-08-16 11:33 ` Per Bothner
1999-08-31 23:20 ` Per Bothner
1999-08-31 23:20 ` R. Kelley Cook
1 sibling, 1 reply; 8+ messages in thread
From: Per Bothner @ 1999-08-16 11:33 UTC (permalink / raw)
To: R. Kelley Cook; +Cc: egcs
"R. Kelley Cook" <KCook@IBM.net> writes:
> > 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;
> > }
> >
>
> yes
Wrong. Try:
i=1;
l1:
if (i++){
//some statements here
i<10; // no-op.
goto l1;
}
I.e. the i++ and i<10 are probably switched ...
--
--Per Bothner
bothner@pacbell.net per@bothner.com http://home.pacbell.net/bothner/
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: about the 'for' statement
1999-08-16 11:33 ` Per Bothner
@ 1999-08-31 23:20 ` Per Bothner
0 siblings, 0 replies; 8+ messages in thread
From: Per Bothner @ 1999-08-31 23:20 UTC (permalink / raw)
To: R. Kelley Cook; +Cc: egcs
"R. Kelley Cook" <KCook@IBM.net> writes:
> > 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;
> > }
> >
>
> yes
Wrong. Try:
i=1;
l1:
if (i++){
//some statements here
i<10; // no-op.
goto l1;
}
I.e. the i++ and i<10 are probably switched ...
--
--Per Bothner
bothner@pacbell.net per@bothner.com http://home.pacbell.net/bothner/
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: about the 'for' statement
1999-08-16 10:54 about the 'for' statement R. Kelley Cook
1999-08-16 11:33 ` Per Bothner
@ 1999-08-31 23:20 ` R. Kelley Cook
1 sibling, 0 replies; 8+ messages in thread
From: R. Kelley Cook @ 1999-08-31 23:20 UTC (permalink / raw)
To: egcs
On 16 Aug 1999 09:03:09 +0200, Wang Yong wrote:
>Hi, all
> in gcc, how 'for' statement is translated?
>
> for example:
>
> for (i=1;i++;i<10){
> //some statement here
> }
>
Strange question, you already wrote enough to check the answer yourself.
All you had to do was change your code to be ...
for (i=1;i++;i<10){
printf("%d",i); //some statement here
}
and you would have realized the answer.
> If this for statement will be translated to something like this :
>
> i=1;
>l1:
> if (i<10){
> //some statements here
> i++;
> goto l1;
> }
>
yes
>or
>
> i=1;
>l1:
> i++;
> if (i<10){
> //some statements here
> goto l1;
> }
no
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: about the 'for' statement
1999-08-16 2:19 ` Branko Cibej
@ 1999-08-31 23:20 ` Branko Cibej
0 siblings, 0 replies; 8+ messages in thread
From: Branko Cibej @ 1999-08-31 23:20 UTC (permalink / raw)
To: Wang Yong; +Cc: gcc maillist
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
^ permalink raw reply [flat|nested] 8+ messages in thread
* about the 'for' statement
1999-08-16 0:02 Wang Yong
1999-08-16 2:19 ` Branko Cibej
@ 1999-08-31 23:20 ` Wang Yong
1 sibling, 0 replies; 8+ messages in thread
From: Wang Yong @ 1999-08-31 23:20 UTC (permalink / raw)
To: gcc maillist
Hi, all
in gcc, 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;
}
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: about the 'for' statement
1999-08-16 0:02 Wang Yong
@ 1999-08-16 2:19 ` Branko Cibej
1999-08-31 23:20 ` Branko Cibej
1999-08-31 23:20 ` Wang Yong
1 sibling, 1 reply; 8+ messages in thread
From: Branko Cibej @ 1999-08-16 2:19 UTC (permalink / raw)
To: Wang Yong; +Cc: gcc maillist
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
^ permalink raw reply [flat|nested] 8+ messages in thread
* about the 'for' statement
@ 1999-08-16 0:02 Wang Yong
1999-08-16 2:19 ` Branko Cibej
1999-08-31 23:20 ` Wang Yong
0 siblings, 2 replies; 8+ messages in thread
From: Wang Yong @ 1999-08-16 0:02 UTC (permalink / raw)
To: gcc maillist
Hi, all
in gcc, 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;
}
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~1999-08-31 23:20 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-08-16 10:54 about the 'for' statement R. Kelley Cook
1999-08-16 11:33 ` Per Bothner
1999-08-31 23:20 ` Per Bothner
1999-08-31 23:20 ` R. Kelley Cook
-- strict thread matches above, loose matches on Subject: below --
1999-08-16 0:02 Wang Yong
1999-08-16 2:19 ` Branko Cibej
1999-08-31 23:20 ` Branko Cibej
1999-08-31 23:20 ` Wang Yong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).