comp.lang.ada
 help / color / mirror / Atom feed
From: Robert Dewar <dewar@gnat.com>
Subject: Re: Representation clause for enumeratives
Date: Sat, 10 Feb 2001 06:29:54 GMT
Date: 2001-02-10T06:29:54+00:00	[thread overview]
Message-ID: <962n4v$fmg$1@nnrp1.deja.com> (raw)
In-Reply-To: LRKg6.1443$y03.158823@news.flash.net

In article <LRKg6.1443$y03.158823@news.flash.net>,
  "Ken Garlington" <Ken.Garlington@computer.org> wrote:
> As an aside, here's some fun you can have with the following
package in GNAT
> 3.12p:
>
> : package Big_Enum is
> :
> :    type Object is  (A, B, C);
> :
> :    for Object use(
> :       16#0000_0002#,
> :       16#0000_0004#,
> :       16#8000_0000#
> :       );

That's fine, GNAT will use a 32-bit unsigned representation

> -- But change it to the following, and you get "value not in
>range of type
> 'Standard.Integer'"
> -- (I only changed the first value to -1; it's not in
Standard.Integer? :)
>
>    for Object use(
>       -1,
>       16#7FFF_FFFF#,
>       16#8000_0000#
>       );

No, it's the 2**31 value at the end (16#8000_0000#) that
is not in the range of Standard.Integer. GNAT will use a
32 bit unsigned representation if it can, but if you use
a negative value, you force the use of a signed representation.
Note that biasing is not an option here, since the values must
denote actual representations.

> -- This works fine....
>
>    for Object use(
>       1,
>       2,
>       16#FFFF_FFFF#
>       );

Because a 32-bit unsigned representation can be used

> -- But the following draws the Standard.Integer message...
>
>    for Object use(
>       -16#FFFF_FFFF#,
>       -2,
>       -1
>       );

Because now a 32-bit unsigned representation cannot be used,
so a 32-bit signed representation must be used and the
first value is out of range.

> Tsk - these limited enumeration representation ranges... :)

Reread the above comments and I think things will be clear.
GNAT does its best to satisfy the semantic requirements, while
obeying the size restriction you have placed. It will choose
either a signed or unsigned representation, extending the
number of cases that can be covered, but it cannot fit more
bits into 32 bits than fit :-)

> I wouldn't mind this behavior in a numeric type...
>
> type Hardware_Numeric is range (-16#8000# .. 16#7FFF#) or (
16#0000# ..
> 16#FFFF#);
>
> A : Hardware_Numeric := -1; -- all further literals must be
in range of
> first clause...
> X : Hardware_Numeric := 16#8000#; -- all further literals
must be in range
> of second clause...
>
> Get that into Ada 0Y for me, will ya? :)

Hmmm! I think we will place more emphasis on the smiley here
than the suggestion :-) :-)

But you are confusing issues here, most certainly the idea of
a single type that somehow flips between signed and unsigned
is of course ludicrous.

But here we have separate types, and the RM quite specifically
does NOT specify limitations on the ranges of values that can
be accepted, so the compiler is free to choose any appropriate
underlying representation type.

Yes, it is definitely a non-required, but very useful, behavior
that GNAT will use either signed or unsigned representations
here (after all, the ability to use a signed representation
gives the original questioner what they wanted).

P.S. The one undesirable behavior in GNAT that I see, and will
fix is that the error flag is not clearly placed on the
particular literal that is causing trouble!

>
>


Sent via Deja.com
http://www.deja.com/



  reply	other threads:[~2001-02-10  6:29 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-02-08  9:53 Representation clause for enumeratives Sandro Binetti
2001-02-08 10:12 ` Tarjei T. Jensen
     [not found]   ` <95u470$ho1$1@nnrp1.deja.com>
     [not found]     ` <95ua6q$mp4$1@nnrp1.deja.com>
2001-02-08 15:41       ` M. Kotiaho
2001-02-08 16:27         ` Steve O'Neill
2001-02-09  7:26           ` Sandro Binetti
2001-02-09  9:29           ` Martin Dowie
2001-02-08 15:55     ` Marin David Condic
2001-02-08 16:22 ` Rod Chapman
2001-02-10  6:34   ` Robert Dewar
2001-02-12 11:32     ` Rod Chapman
2001-02-08 18:52 ` Greg Bek
     [not found] ` <Ndyg6.1048$y03.96769@news.flash.net>
2001-02-09  5:02   ` Ken Garlington
2001-02-10  6:29     ` Robert Dewar [this message]
2001-02-10 16:37       ` Ken Garlington
2001-02-10 17:29         ` Robert Dewar
2001-02-11  1:09           ` Ken Garlington
2001-02-11  5:27             ` Robert Dewar
2001-02-11 12:53               ` Laurent Guerby
2001-02-12  0:24                 ` Robert Dewar
2001-02-12 20:10                   ` Laurent Guerby
2001-02-11 14:50               ` Ken Garlington
2001-02-10 17:31         ` Robert Dewar
2001-02-11  1:09           ` Ken Garlington
2001-02-11  5:28             ` Robert Dewar
2001-02-11 14:50               ` Ken Garlington
2001-02-12  0:30                 ` Robert Dewar
2001-02-12  2:34                   ` Ken Garlington
2001-02-10  6:19   ` Robert Dewar
2001-02-10 11:42     ` David C. Hoos, Sr.
2001-02-10 16:37     ` Ken Garlington
     [not found] ` <3A829EB8.A098925E@baesystems.com>
     [not found]   ` <95uae3$n5j$1@nnrp1.deja.com>
2001-02-12  9:12     ` Stuart Palin
replies disabled

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