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:17:23 +0100 Organization: A noiseless patient Spider Lines: 25 Message-ID: References: <87bn977v7v.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Injection-Date: Wed, 30 Dec 2015 17:14:46 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="dc28719e2ffeeb5899be5f5057009353"; logging-data="19850"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/4ZBqLKkbbNq6x75fGjLKGYKkMJgGeVMg=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 In-Reply-To: <87bn977v7v.fsf@bsb.me.uk> Cancel-Lock: sha1:pQfI7uUeQstgW2Q6WGcx2Jy5t0o= Xref: csiph.com comp.programming:6083 On 30/12/15 17:32, Ben Bacarisse wrote: > David Brown writes: > >> On 30/12/15 14:28, Richard Heathfield wrote: > >>> int i = -6; >>> unsigned int j = 42; >>> if(i < j) >>> { >>> puts("-6 is less than 42"); >>> } > >> Of course, this in itself is just a specialist case of the difference >> between "normal" mathematics and numbers in C. Replace the first two >> lines with "int16_t i = 1000000; int16_t j = 4000000;" and you'll find >> that four million is apparently smaller than one million. > > You might find that, but you also might not! There is a conversion > which is implementation-defined (and might even raise a signal). > Absolutely - which is why you always have to be careful with arithmetic in C.