Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c Subject: Re: "How one word broke C" Date: Fri, 27 Mar 2020 07:18:52 -0700 Organization: A noiseless patient Spider Lines: 35 Message-ID: <86v9mp98z7.fsf@linuxsc.com> References: <91u7kg-ap03.ln1@mail.home.palmen-it.de> <5a2a8006-dac6-45d2-985a-f6b9f5f3fb32@googlegroups.com> <1%AcG.171306$8h.41300@fx26.iad> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="02cbe0882c270f81c5b8b4aa13e82222"; logging-data="10934"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18I4A67KhAvm5YY3j2u7fLmtznheHkNel0=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:BgbT/PrQHTUR2yDcQVxTzLLVj7c= sha1:YR5vDrhXQsYRG1Fj620ngja8PJU= Xref: csiph.com comp.lang.c:150858 Richard Damon writes: > On 3/18/20 4:06 PM, Philipp Klaus Krause wrote: > >> Am 18.03.20 um 20:11 schrieb already5chosen@yahoo.com:> Itanium is quite >> similar to few other supported gcc targets. Yet >> >>> another byte-addressable machine with two-complement arithmetic, >>> 4byte words, 8byte double words and 8byte pointers, run-of-the-mill >>> assortment of arithmetic, logic and shift operations. And absence of >>> integer divide instruction is not extraordinary. Mandatory "natural" >>> alignment of 4-byte and 8-byte numbers is required by few other gcc >>> targets as well. So, generation of correct Itanium code is quite >>> easy. >> >> Thanks to undefined behaviour. Otherwise the trap representations would >> be a problem (reading uninitialized local variables can actually crash >> programs on Itanium). > > That behavior is actually quite old. There were machines that had > instructions to erase a word of core to a bad memory value (bad parity) > and if that word was later read before it was written to the program > would trap on the parity error. Yes but such things have not always been undefined behavior. In C90, reading any uninitialized (auto) variable is UB. In C99, reading an uninitialized variable is UB only if the stored value is a trap representation; a type that doesn't have any trap representations (which these days includes most integer types in most implementations) cannot transgress into UB land. It wasn't until C11 that the Standard added a provision that specifies UB for such accesses, and even then only for variables that do not have their address taken. It is the C11 rule that allows UB for Itanium-style variables, which can trap even though their type has no trap representations.