comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Unclear error message - please help
Date: 09 Oct 2005 10:24:16 -0400
Date: 2005-10-09T10:24:16-04:00	[thread overview]
Message-ID: <wccu0fqpy3z.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: 4894486.ZC6T0HgaI8@linux1.krischik.com

Martin Krischik <krischik@users.sourceforge.net> writes:

> Alfred Hilscher wrote:
> 
> >   subtype
> >     Sixteen_Bits is Integer range 0..65535;
> 
> The name "Sixteen_Bits" suggest a different implementation:
> 
> type Sixteen_Bits is mod 2 ** 16;
> for Sixteen_Bits'Size use 16;
> 
> A "range 0..65535" needs 17 bits and an "is Integer" is usually 32 bit.

I don't really agree with that advice.  Modular types should be used
only in certain rare circumstances.  (They are, perhaps, my least
favorite feature of Ada.)

Anyway, Sixteen_Bits is 16 bits.  I mean, Sixteen_Bits'Size = 16.
There's no implementation choice here -- that's required of all
implementations.  And you can use rep clauses or pragmas Pack
to ensure that objects of this subtype are actually allocated
16 bits.  Without such clauses or Pack, the compiler is free
to do whatever it likes -- probably allocate 32 bits for each object.
17 bits is pretty unlikely!  ;-)

Arithmetic will be done in the base range, however -- you'll get
overflows past Integer'First..Integer'Last, not 0..2**16-1.

> See
> 
> http://en.wikibooks.org/wiki/Ada_Programming/Types/range
> http://en.wikibooks.org/wiki/Ada_Programming/Types/mod
> 
> for more info.

- Bob



  reply	other threads:[~2005-10-09 14:24 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-17 21:11 Unclear error message - please help Alfred Hilscher
2005-09-17 21:44 ` Gene
2005-09-17 22:02 ` Ludovic Brenta
2005-09-18  2:32 ` Robert A Duff
2005-10-08 19:39   ` Alfred Hilscher
2005-10-08 20:15     ` Björn Persson
2005-10-09  7:34       ` Martin Krischik
2005-10-08 21:28     ` Dmitry A. Kazakov
2005-10-08 23:58     ` Robert A Duff
2005-10-09  7:29     ` Martin Krischik
2005-10-09 14:24       ` Robert A Duff [this message]
2005-10-09 22:02       ` Brian May
2005-10-10 16:49         ` Martin Krischik
2005-10-10 22:20           ` Brian May
2005-10-11  5:48             ` Martin Dowie
2005-10-11 18:03             ` Martin Krischik
     [not found]         ` <h84lk1tqgofrhgabm8q3sqbb80li6733bh@4ax.com>
2005-10-16  1:10           ` Robert A Duff
replies disabled

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