home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.os.linux
- Path: sparky!uunet!gatech!darwin.sura.net!jvnc.net!primerd.prime.com!tiger1.prime.com!cummings
- From: cummings@tiger1.prime.com (Kevin J. Cummings)
- Subject: Re: GCC 2.2.2d bug
- Message-ID: <1992Sep4.174212@tiger1.prime.com>
- Followup-To: comp.lang.c
- Sender: usenet@primerd.prime.com (Usenet)
- Organization: Prime Computer, Inc.
- References: <1992Sep4.202913.14346@hippo.ru.ac.za>
- Date: Fri, 4 Sep 1992 21:42:12 GMT
- Lines: 55
-
- In article <1992Sep4.202913.14346@hippo.ru.ac.za>, pi@oliver.sun.ac.za (Pieter Immelman) writes:
- > I have found that gcc is generating the wrong code for the following
- > code fragment:
- >
- > int p = 10;
- > p = p++;
- >
- > From my C background, I have found the value to be 10. Unfortunately
- > (for the gcc maintainers) the result is 11.
-
- Actually, it depends upon whether or not the post increment happens before
- or after the assign of p into p, and if before, then upon whether the old
- value of p is saved in a register before the post increment gets done.
- Not a construct I would get all upset about. Anyone writing this kind of code
- deserves more flames than the compiler writer who didn't handle it right B^).
-
- > gcc -s produces the following:
- >
- > movl $10,-4(%ebp)
- > movl -4(%ebp),%edx
- > movl %edx,-4(%ebp)
- > incl -4(%ebp)
- >
- > As I see it the "incl" is done at the wrong place. It should be done
- > right after the value of "p" was used. The incrementing is done after
- > the assignment; in my opinion it must be done right after obtaining the
-
- I was under the impression that the increment could be done any time after the
- value for the expression was produced. Has the ANSI C standard defined it any
- further than that? If not, then it really is an implementation defined
- result, and may therefore vary from implementation to implementation. I don't
- have my C standard with me right now to say for sure, but surely there are
- better problems in LINUX to complain about? Followups are directed to comp.lang.c.
-
- > value... For more fun, try "p = p++ + p++". The value should be 21,
- > but in this case it is 22!
- >
- > Any ideas anyone?
- > --
- > Pieter Immelman (pi@cs.sun.ac.za) Telephone: +27 2231 774393
- > Department of Computer Science, University of Stellenbosch, South Africa
-
- --
- =================================================================
- Kevin J. Cummings PrimeService
- 20 Briarwood Road A Computervision Company
- Framingham, Mass. 500 Old Connecticut Path
- Framingham, Mass.
- Work: cummings@primerd.Prime.COM
- Home: cummings@kjc386.framingham.ma.us
-
- Std. Disclaimer: "Mr. McKittrick, after careful consideration,
- I've come to the conclusion that your new
- defense system SUCKS..." -- War Games
- =================================================================
-