public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: Songtao Chen <songtao@cisco.com>
To: Neil Booth <neil@daikokuya.co.uk>
Cc: gcc-bugs@gcc.gnu.org
Subject: Re: Is this a bug?
Date: Thu, 02 Jan 2003 23:00:00 -0000 [thread overview]
Message-ID: <4.3.2.7.2.20030102173856.01f3e0c0@toque.cisco.com> (raw)
In-Reply-To: <20030102214552.GA13907@daikokuya.co.uk>
Hi Neil,
Thanks for the explanation.
My original problem was this,
#include<stdio.h>
int main(void)
{
int r, i;
i = 0;
i = ++i % 2;
printf("test 1 : i = %d\n", i);
i = 0;
i = i++ % 2;
printf("test 2 : i = %d\n", i);
return 0;
}
Test 2 gives 0. I was expecting 1. Should it not?
Here is the disassembled version, maybe you can tell
what's going on. I don't know much about assembly code.
i = 0;
1083c: c0 27 bf e8 clr [ %fp + -24 ]
i = ++i % 2;
10840: d0 07 bf e8 ld [ %fp + -24 ], %o0
10844: 92 02 20 01 add %o0, 1, %o1
10848: 90 10 00 09 mov %o1, %o0
1084c: d0 27 bf e8 st %o0, [ %fp + -24 ]
10850: 93 3a 20 1f sra %o0, 0x1f, %o1
10854: 95 32 60 1f srl %o1, 0x1f, %o2
10858: 92 02 00 0a add %o0, %o2, %o1
1085c: 95 3a 60 01 sra %o1, 1, %o2
10860: 92 10 00 0a mov %o2, %o1
10864: 95 2a 60 01 sll %o1, 1, %o2
10868: 90 22 00 0a sub %o0, %o2, %o0
1086c: d0 27 bf e8 st %o0, [ %fp + -24 ]
printf("test 1 : i = %d\n", i);
10870: 13 00 00 42 sethi %hi(0x10800), %o1
10874: 90 12 61 78 or %o1, 0x178, %o0 ! 10978
<_lib_version+0x8>
10878: d2 07 bf e8 ld [ %fp + -24 ], %o1
1087c: 40 00 40 6d call 20a30 <_PROCEDURE_LINKAGE_TABLE_+0x6c>
10880: 01 00 00 00 nop
i = 0;
10884: c0 27 bf e8 clr [ %fp + -24 ]
i = i++ % 2;
10888: d0 07 bf e8 ld [ %fp + -24 ], %o0
1088c: 92 02 20 01 add %o0, 1, %o1
10890: d2 27 bf e8 st %o1, [ %fp + -24 ]
10894: 93 3a 20 1f sra %o0, 0x1f, %o1
10898: 95 32 60 1f srl %o1, 0x1f, %o2
1089c: 92 02 00 0a add %o0, %o2, %o1
108a0: 95 3a 60 01 sra %o1, 1, %o2
108a4: 92 10 00 0a mov %o2, %o1
108a8: 95 2a 60 01 sll %o1, 1, %o2
108ac: 90 22 00 0a sub %o0, %o2, %o0
108b0: d0 27 bf e8 st %o0, [ %fp + -24 ]
printf("test 2 : i = %d\n", i);
108b4: 13 00 00 42 sethi %hi(0x10800), %o1
108b8: 90 12 61 90 or %o1, 0x190, %o0 ! 10990
<_lib_version+0x20>
108bc: d2 07 bf e8 ld [ %fp + -24 ], %o1
108c0: 40 00 40 5c call 20a30 <_PROCEDURE_LINKAGE_TABLE_+0x6c>
108c4: 01 00 00 00 nop
return 0;
Thanks for your help.
Songtao
At 09:45 PM 1/2/2003 +0000, Neil Booth wrote:
>Songtao Chen wrote:-
>
> > Hi Neil,
> >
> > Thanks for replying.
> >
> > Can you tell me why the parentheses are irrelevant,
> > any doc to support that?
>
>For the same reason that (2) is the same as 2, and not 3. Like I said,
>post-increment returns the value before incrementing.
>
>Neil.
>
> >
> > Songtao
> >
> > At 09:23 PM 1/2/2003 +0000, Neil Booth wrote:
> > >Songtao Chen wrote:-
> > >
> > >> Hi there,
> > >>
> > >> It appears to be a bug to me.
> > >
> > >No, i++ returns the value before increment. Parentheses are irrelevant.
> > >
> > >Neil.
> >
next prev parent reply other threads:[~2003-01-02 23:00 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-01-02 21:21 Songtao Chen
2003-01-02 21:24 ` Neil Booth
2003-01-02 21:42 ` Songtao Chen
2003-01-02 21:46 ` Neil Booth
2003-01-02 23:00 ` Songtao Chen [this message]
2003-01-13 5:17 ` Zack Weinberg
2003-01-13 5:17 ` Songtao Chen
-- strict thread matches above, loose matches on Subject: below --
2003-08-21 9:23 Lev Assinovsky
2003-02-06 21:33 Matthew Toseland
2003-02-06 22:18 ` Falk Hueffner
2002-08-30 2:41 Ritzert
2002-09-03 14:07 ` Matt Austern
2002-09-10 1:06 ` Michael Ritzert
2000-12-06 3:42 Martin Kahlert
2000-01-30 16:44 Kuo Yu Chuang
[not found] <007d01bf6988$d2fb0c40$795d608c@ccl.itri.org.tw>
2000-01-30 2:45 ` Martin v. Loewis
1999-05-11 21:09 Christian II
1999-05-11 23:44 ` Martin v. Loewis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4.3.2.7.2.20030102173856.01f3e0c0@toque.cisco.com \
--to=songtao@cisco.com \
--cc=gcc-bugs@gcc.gnu.org \
--cc=neil@daikokuya.co.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).