comp.lang.ada
 help / color / mirror / Atom feed
From: "BartC" <bc@freeuk.com>
Subject: Re: condition true or false? ->  (-1 < sizeof("test"))
Date: Tue, 22 May 2012 10:55:01 +0100
Date: 2012-05-22T10:55:01+01:00	[thread overview]
Message-ID: <jpfnqe$8t4$2@dont-email.me> (raw)
In-Reply-To: <eb42d1e8b4d1e87bc804d05ec6964bc3@dizum.com>

"Nomen Nescio" <nobody@dizum.com> wrote in message
news:eb42d1e8b4d1e87bc804d05ec6964bc3@dizum.com...
> glen herrmannsfeldt <gah@ugcs.caltech.edu> wrote:

>> I don't know how ADA treats signed values, or how its bitwise
>> operators work. This is still posted to the ADA group, though.
>
> I'm not an expert on this but Ada is very strongly (statically) typed.
> There
> are only two integer types in Ada to start with, signed integer and
> modular
> integer. The compiler will flag an error if you try to compare variables
> of
> those two types or indeed variables of any differing types.

Signed and modular is a better way of explaining how C treats these types,
with a clear distinction between them.

Signed types clearly should be the primary way to represent actual integer
quantities as most of us think of them. A signed integer range can represent
any positive value (given enough bits); an unsigned range can't represent
any positive or  negative value (not with a finite number of bits anyway).

That's why it's odd that when there is any hint of a unsigned operand, C
should switch to modular arithmetic for both.

But, given that C works at a lower level, and the choice of bit-widths is
limited, then perhaps there ought to be 3 integer types:

- Signed
- New-unsigned
- Modular

With the new-unsigned type behaving as I have suggested a few times [in the
original thread in comp.lang.c], just a subrange of a signed type (for
example, a hypothetical signed integer type that is one bit wider).

With the new-unsigned type, a negation operation must have signed result
(because, other than -0, it will be negative). While subtraction would need
to be signed too, as results can be negative. And of course there is the 
likelihood of overflow or underflow, for which I will leave to other 
language proposals to deal with..

-- 
Bartc 




  parent reply	other threads:[~2012-05-22  9:56 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <95634f38f6ee0d116da523fdc2c9f5ca@dizum.com>
2012-05-21 15:28 ` condition true or false? -> (-1 < sizeof("test")) Nomen Nescio
2012-05-21 15:37   ` Richard Maine
2012-05-21 15:45   ` Adam Beneschan
2012-05-21 17:16     ` Robert A Duff
2012-05-22  1:08   ` Terence
2012-05-22  7:54     ` Les Neilson
2012-05-22 23:19       ` Terence
2012-05-23  7:20         ` Les Neilson
2012-05-22 15:43     ` Fritz Wuehler
2012-05-22  1:45   ` glen herrmannsfeldt
2012-05-22  6:11     ` Nomen Nescio
2012-05-22  8:00       ` Martin
2012-05-22  9:55       ` BartC [this message]
2012-05-22 12:07         ` Dmitry A. Kazakov
2012-05-22 16:25           ` BartC
2012-05-22 17:03             ` Dmitry A. Kazakov
2012-05-22 17:26               ` BartC
2012-05-22 18:18                 ` Dmitry A. Kazakov
2012-05-23  7:26                   ` Terence
2012-05-22 17:56         ` Fritz Wuehler
2012-05-22 10:29     ` Georg Bauhaus
2012-05-30  3:22   ` robin.vowels
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox