From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11082 invoked by alias); 28 Jun 2005 17:18:05 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 11033 invoked by uid 22791); 28 Jun 2005 17:17:55 -0000 Received: from dspnet.fr.eu.org (HELO dspnet.fr.eu.org) (213.186.44.138) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Tue, 28 Jun 2005 17:17:55 +0000 Received: by dspnet.fr.eu.org (Postfix, from userid 1007) id 25DD334D2D; Tue, 28 Jun 2005 19:17:53 +0200 (CEST) Date: Tue, 28 Jun 2005 17:18:00 -0000 From: Olivier Galibert To: Andrew Haley Cc: Dave Korn , 'Robert Dewar' , 'Gabriel Dos Reis' , 'Andrew Pinski' , 'gcc mailing list' Subject: Re: signed is undefined and has been since 1992 (in GCC) Message-ID: <20050628171752.GE52889@dspnet.fr.eu.org> References: <20050628142441.GA52889@dspnet.fr.eu.org> <20050628145148.GD52889@dspnet.fr.eu.org> <17089.26325.169281.749633@zapata.pink> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <17089.26325.169281.749633@zapata.pink> User-Agent: Mutt/1.4.2.1i X-SW-Source: 2005-06/txt/msg01152.txt.bz2 On Tue, Jun 28, 2005 at 04:03:49PM +0100, Andrew Haley wrote: > Olivier Galibert writes: > > On Tue, Jun 28, 2005 at 03:39:38PM +0100, Dave Korn wrote: > > > ----Original Message---- > > > >From: Olivier Galibert > > > >Sent: 28 June 2005 15:25 > > > > > > > In particular, a very large number of C and C++ programs are written > > > > with the assumptions: > > > > > > This is a bad line of reasoning in general. There is a vast amount of bad > > > software in the world, some blatantly buggy, some subtly-incorrect. To > > > attempt to fix it all in the compiler rather than the source seems a bit > > > bass-ackwards to me! > > > > Welcome to the real world. Useful compilers are not an exercise in > > theorical computing, especially for languages like C or C++. > > This is childish and insulting. Calling a large part of the programs out there, including a non negligible subpart of what I personally write either "blatantly buggy" or "subtly-incorrect" is somewhat childish and insulting. > The standard of discourse on this list has been dropping of late, and > we'd all get a lot more done if we'd learn to take a deep breath > before posting. Try to remember this is a technical discussion, not > an argument in a bar. Lemme give the long version then. C has been created as a system programming language[1], and is still _the_ system programming language. Its types are by design very dependant on the real hardware, and even its behaviour. And the standardization, probably to the great chagrin of language theorists, has been careful to reflect that, leaving large areas underspecified to allow both the compiler and the programmer to rely on the appropriate hardware-defined behaviour where useful. Knowing what you run on is not being subtly incorrect, it's being an engineer instead of a theorist. Languages which try to define every behaviour independently of the hardware either run on virtual machines or require the help of Hossein Rezazadeh to move the specs around. Now, given this hardware dependance of the language on one side and a desire for reasonable portability on the other there pretty much exists classes of hardware a given program will compile and run on. Only theorical, and essentially uninteresting, programs will run on everything. The main class today is the one I was talking about: - 8 bits char, 16 bits short, 32 bits int, 64 bits long long - 2-complement without surprises, with the exception that overflow on loop induction variables is essentially always a bug - long is the same size as pointer (intptr_t is not very accepted yet), pointer to function and pointer to data have the same size - 32 and 64 bits ieee for float and double - null pointer is all bits 0 - volatile means something can modify the value at any time - memory is naturally byte-accessible, you just have to be careful with alignments (and even then it's often considered that the OS should provide transparent unaligned accesses if the hardware doesn't do it by itself) And probably some others I'm forgetting. Thinking that programs which rely on these assumptions are incorrect is the attitude of a theorist with his head in the sand. The kind of people that should never be left anywhere near the source of a C compiler. And to break themyou need a really, compelling hardware reason. Breaking sizeof(void *) == sizeof(int) took years for people and programs to adapt and is still not completely there yet. Breaking aliasing took a while too. Even embedded hardware tend to converge on that class for flexibility and interoperability reasons. Those who aren't there yet keep a very, very close control on their software environment and don't plan to run anything they find on sourceforge without a large amount of effort. And they use the C compiler even more as a high-level assembler than most people. Anyway, my point is that breaking these assumptions just because the standard does not specify them is silly. They're driven by the hardware, not by the wishes of compiler writers or of language theorists. OG. [1] http://cm.bell-labs.com/cm/cs/who/dmr/chist.html