Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: gcc failure (optimised/non-optimised) Date: Mon, 24 Apr 2017 08:33:47 -0700 Organization: None to speak of Lines: 30 Message-ID: References: <87shl0enji.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="b06baaefdd2d8c25f7a310fe1662b016"; logging-data="25672"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18i2zYYhuP5sioIyGTs6sI/" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:4E/wKftXyA7XHxM6qUoue+zi1ik= sha1:n7/obG5WTR3dreiEZezh4EmIpHY= Xref: csiph.com comp.lang.c:108407 James Harris writes: > On 22/04/2017 11:37, Gareth Owen wrote: >> James Harris writes: [...] >>> What gets me is that the compiler is (potentially) altering the >>> behaviour of the code without issuing a warning. That's true even with >>> -Wall -Wextra. >> >> The code does not have (defined) behaviour. Code whose behaviour is not >> defined, does not have to consistent modes of misbehaviour. > > That's the correct "C" position, of course, and I understand it. > However, I am uncomfortable with a compiler changing the effect of the > code without warning. Consider this: char message[5] = "hello"; puts(message); This has undefined behavior because `message` does not contain a (valid null-terminated) string. Its actual behavior is likely to vary depending on optimization level and other compiler options. Does that make you equally uncomfortable? -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"