home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!news.funet.fi!hydra!klaava!wirzeniu
- From: wirzeniu@klaava.Helsinki.FI (Lars Wirzenius)
- Newsgroups: comp.os.linux
- Subject: Re: GCC 2.2.2d bug
- Message-ID: <1992Sep5.085026.12800@klaava.Helsinki.FI>
- Date: 5 Sep 92 08:50:26 GMT
- References: <1992Sep4.202913.14346@hippo.ru.ac.za> <1992Sep05.013320.2317@kithrup.COM>
- Organization: University of Helsinki
- Lines: 27
-
- dje@cygnus.com (Doug Evans) writes:
- >Pieter Immelman (pi@oliver.sun.ac.za) wrote:
- >: I have found that gcc is generating the wrong code for the following
- >: code fragment:
- >:
- >: int p = 10;
- >: p = p++;
- >
- >My, albeit limited, reading of the standard says that the behaviour
- >is "unspecified" - the implementor can choose what happens.
-
- It's undefined behaviour. The problem is that the program alters the
- same memory location multiple times between two sequence points (which
- are points in execution when all side effects of previous expressions
- are guaranteed to have been completed).
-
- There are two things which a compiler can do about undefined behaviour:
- make it work in one way or another, even if it might be unobvious to
- some people, or make it produce spectacular effects (core dumps, clay
- pidgeons flying out of the user's ears, etc). The latter is, of course,
- preferred, since it makes the problem more obvious than either incorrect
- output, or code that just happens to work right. But as far as
- correctness is concerned, any output at all, or even no output, is
- legal.
-
- --
- Lars.Wirzenius@helsinki.fi
-