Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: David Brown Newsgroups: comp.programming Subject: Re: Here is why C++ and C are bad... Date: Wed, 30 Dec 2015 18:19:29 +0100 Organization: A noiseless patient Spider Lines: 55 Message-ID: References: <87h9j06ip1.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Injection-Date: Wed, 30 Dec 2015 17:16:52 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="dc28719e2ffeeb5899be5f5057009353"; logging-data="19850"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18dVNwGBKwS54JHTQ+NMUavrJXMa1pgkEs=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 In-Reply-To: Cancel-Lock: sha1:xXpcZuq24klrzY6t474Derry/MM= Xref: csiph.com comp.programming:6084 On 30/12/15 17:35, Richard Heathfield wrote: > On 30/12/15 15:48, Ben Bacarisse wrote: > > > >> Since this is comp.programming, you should perhaps have said that mixing >> signed and unsigned expressions _in C_ is often a bad sign. It may be >> in other languages too, but there are others in which it is both common >> and harmless. > > Fair comment. So perhaps we could start by looking at how some other > languages deal with unsigned integer types (or indeed whether they > support them at all). I should say at the outset that the information I > present below is unsatisfactorily sparse. > > Ada supports signed and unsigned integer types. I couldn't find any > rules on how mixed-sign arithmetic is done (but that doesn't mean there > aren't any). > > BASIC - tricky one. ISO/IEC 10279 defines the language, but I couldn't > find a freely available draft. > > COBOL (according to a rather strangely-formatted draft ISO Standard from > 2005) seems to support unsigned char, short, long, and even double. It > isn't clear (from a quick scan) how COBOL deals with mixed-sign arithmetic. > > D's rules are similar to C's. Particularly, if the two types are of the > same size, then the signed type is converted to unsigned. > > Eiffel supports unsigned integer types, but I found nothing in ECMA-367 > to show how they interact with signed types. > > Fortran's draft standard (n3501) is rather odd. In Note 15.9 we find > that "...Fortran does not provide direct support for unsigned kinds of > integers", and yet in 4.4.1 Integer Type the text reads "The value of a > signed integer zero is the same as the value of an unsigned integer > zero", which suggests that there is /some/ kind of support for unsigned > integers. > > Go supports unsigned integer types, but a brief perusal of the spec > didn't turn up any rules for mixed-sign arithmetic. > > I ran out of time to extend this alphabetical list any further, but one > of the first languages I thought of was PHP. I found it surprising that > PHP doesn't appear to support an unsigned integer type (something that > it has never before occurred to me to check, which suggests to me that I > don't use PHP quite as often as I thought I did). > You didn't get as far as Python, I take it. In Python, the integer types just get as big as you need (until you run out of time or memory). So to a large extent you can assume your integers really are mathematical integers, and add them as much as you want. (So "unsigned" integers don't really exist.)