home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cis.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!ukma!rutgers!psinntp!psinntp!pool!ujlh
- From: ujlh@pool.info.sunyit.edu (James Henrickson)
- Newsgroups: comp.os.linux
- Subject: Re: GCC 2.2.2d bug
- Message-ID: <1992Sep6.162717.24242@pool.info.sunyit.edu>
- Date: 6 Sep 92 16:27:17 GMT
- References: <1992Sep4.202913.14346@hippo.ru.ac.za> <1992Sep4.230902.2523@novell.com>
- Organization: State University of New York -- Institute of Technology
- Lines: 33
-
- In article <1992Sep4.230902.2523@novell.com> bboerner@novell.com (Brendan B. Boerner) writes:
- >In article <1992Sep4.202913.14346@hippo.ru.ac.za> pi@cs.sun.ac.za 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.
- >
- >I have this idea that if you posted this to comp.lang.c, Chris Torek or
- >someone similar would point out that this is correct behaviour. My gut
- >feeling is that it SHOULD be 11 but I'm not a C guru.
-
- Since the value of p isn't used for anything, it looks like the compiler
- is optimizing it for you. Here's another test:
-
- printf("%d\n",(p = p++));
- printf("%d\n",p);
-
- The results should, I think, be:
- 10
- 11
-
- The post-increment and post-decrement operations are performed after
- they have been used, such as in "for" loops.
-
- --
- Jim H.
- *
- * James L. Henrickson
- * ujlh@sunyit.edu "Some day I might have a real .signature!"
-