home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!elroy.jpl.nasa.gov!news.claremont.edu!ucivax!news.service.uci.edu!cerritos.edu!wilbur!orville!kryton!system
- Newsgroups: comp.os.linux
- Subject: Re: GCC 2.2.2d bug
- Message-ID: <8eToqB1w164w@kryton.UUCP>
- From: system@kryton.UUCP (Scott Beckstead)
- Date: Sun, 06 Sep 92 09:09:54 PDT
- References: <1992Sep4.210545.36040@uservx.plk.af.mil>
- Organization: Paradox Alley F&SF BBS 805-492-8789
- Lines: 59
-
- simonich@uservx.plk.af.mil writes:
-
- > In article <1992Sep4.230902.2523@novell.com>, bboerner@novell.com (Brendan B.
- > > 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.
- > >
- > > Later,
- > > Brendan
- > > --
- > > Brendan B. Boerner Phone: 512/346-8380
- > > Internet: bboerner@novell.com MHS: bboerner@novell
- > > Please use ^^^^^^^^^^^^^^^^^ if replying by mail.
- >
- > I will admit that it isn't the ASCII C standard but on page 46 of
- > The C Programming Language (second edition) by Kernighan and Ritchie
- > they give the specific example:
- > "If n is 5, then
- >
- > x = n++;
- >
- > sets x to 5, but
- >
- > x = ++n;
- >
- > sets x to 6."
- > I agree with a previous poster that this code fragment is IMHO, very
- > poor code.
-
- Indeed very poor code. The final result will be 11. because even if
- the assign works properly the increment will still happen. I know
- the the gnu code here works properly. This kind of bug could be so
- subtle that it might easily never be found. It is also probably
- going to be optimized to merely :
- p++;
- instead of having any other effect. Which is properly the semantic
- equivalent of this code fragment.
-
- Scott
-
-
-
-
-
-
- System Administrator Paradox Alley F&SF BBS and Usenet News/Mail
- 805-492-8789 Thousand Oaks, Ca. The Place For Science Fiction and Fantasy
- "Spin My Nipple Nuts and Send Me to Alaska!" Kryten, Red Dwarf
-
-