comp.lang.ada
 help / color / mirror / Atom feed
From: Nomen Nescio <nobody@dizum.com>
Subject: Re: condition true or false? ->  (-1 < sizeof("test"))
Date: Tue, 22 May 2012 08:11:54 +0200 (CEST)
Date: 2012-05-22T08:11:54+02:00	[thread overview]
Message-ID: <eb42d1e8b4d1e87bc804d05ec6964bc3@dizum.com> (raw)
In-Reply-To: jper36$8t8$1@speranza.aioe.org

glen herrmannsfeldt <gah@ugcs.caltech.edu> wrote:

> In comp.lang.fortran Nomen Nescio <nobody@dizum.com> wrote:
> (snip) 
> >> > >     Negation of unsigned 1 (which can be written `-1u') is already
> >> > > defined in C, although there are implementation-defined aspects.
> >> > > In particular, there are no "overflow issues," usual or otherwise.
> 
> Note that in C this is applying the unary - operator to the
> constant 1u. 
> 
> In Fortran, except in rare cases (the DATA statement being one)
> constants are not signed. (The implentation may apply the unary
> minus operator before generating the in-memory constant.)
> 
> I would usually write ~0u instead of -1u, but the result is
> the same in both cases. 
> 
> In Fortran, one could write NOT(0), with the usual restriction
> on the bitwise operators on values with the sign bit set.
> (In addition to the fact that Fortran doesn't require a binary
> representation for data.)
> 
> 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. You can define
subtypes of existing types and completely new types and Ada insures you
can't make mistakes by mixing apples and oranges. While this is a bit
confining at times (when you know it's ok to do so) it does preclude the
possibility of something like what Bartc wrote from ever happening. If you
know the conversion is ok there are ways (usually by providing an unchecked
conversion function) to assign or compare across types.













  reply	other threads:[~2012-05-22  6:12 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 [this message]
2012-05-22  8:00       ` Martin
2012-05-22  9:55       ` BartC
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