comp.lang.ada
 help / color / mirror / Atom feed
From: Keith Thompson <kst-u@mib.org>
Subject: Re: Problem with Position of the enumeration Type
Date: Wed, 23 Jan 2019 15:47:05 -0800
Date: 2019-01-23T15:47:05-08:00	[thread overview]
Message-ID: <lnimyf0wee.fsf@kst-u.example.com> (raw)
In-Reply-To: q2arbb$p10$1@franka.jacob-sparre.dk

"Randy Brukardt" <randy@rrsoftware.com> writes:
> "Simon Wright" <simon@pushface.org> wrote in message 
> news:lyzhrruww2.fsf@pushface.org...
> ...
>> As Karl Müller <mtb23@gmx.de> hinted, you can use the non-standard GNAT
>> implementation-defined attribute 'Enum_Rep[1]. The next page describes
>> 'Enum_Val.
>
> It's Standard, just not until Ada 2020. See 
> http://www.ada-auth.org/standards/2xrm/html/RM-13-4.html#p10.1.
>
> (Yes, borrowed from GNAT.)

I'm glad to see this being standardized.

Unchecked_Conversion can be a workaround, but it's difficult
(perhaps impossible) to portably determine the integer type to
which you need to convert.

For example, both of these are valid:

    type Unsigned_Byte is (UMin, UMax);
    for Unsigned_Byte use (0, 255);
    for Unsigned_Byte'Size use 8;

    type Signed_Byte is (SMin, SMax);
    for Signed_Byte use (-128, 127);
    for Signed_Byte'Size use 8;

Both types will have the same representation for the min and max values.
How can you *portably* determine the appropriate target type for an
Unchecked_Conversion that yields the correct values?

(You can do it manually on a case by case basis.)

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */

  reply	other threads:[~2019-01-23 23:47 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-23 10:05 Problem with Position of the enumeration Type Luis Ladron de Guevara Moreno
2019-01-23 10:33 ` AdaMagica
2019-01-23 10:55   ` AdaMagica
2019-01-23 12:08   ` Luis Ladron de Guevara Moreno
2019-01-23 12:15     ` Karl Müller
2019-01-23 21:50     ` Niklas Holsti
2019-01-24  8:06     ` AdaMagica
2019-01-23 11:32 ` Mark Lorenzen
2019-01-23 12:30   ` Luis Ladron de Guevara Moreno
2019-01-23 20:22     ` Shark8
2019-01-24  8:13       ` AdaMagica
2019-01-23 17:06 ` Simon Wright
2019-01-23 22:54   ` Randy Brukardt
2019-01-23 23:47     ` Keith Thompson [this message]
2019-01-24  4:34       ` Keith Thompson
2019-01-24  9:11         ` Simon Wright
2019-01-24 21:41       ` Randy Brukardt
2019-01-23 21:42 ` Niklas Holsti
2019-01-23 22:35   ` Simon Wright
2019-01-23 23:20     ` Niklas Holsti
2019-01-24 16:43     ` Jeffrey R. Carter
2019-01-24 19:39       ` Niklas Holsti
2019-01-24 20:29         ` Jeffrey R. Carter
2019-01-24 21:43         ` Randy Brukardt
2019-01-26  9:44   ` G.B.
replies disabled

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