From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.ada Subject: Re: Problem with Position of the enumeration Type Date: Wed, 23 Jan 2019 15:47:05 -0800 Organization: None to speak of Message-ID: References: <3d782720-227d-4d86-b403-eacbd1b9d0d2@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: reader02.eternal-september.org; posting-host="408bb0283150d2fd02799035b8169951"; logging-data="3918"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+oYa8zzpb1T47GaMprqvzC" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:b6y2Cd/wouZwKsE+MIt8ZBy0loA= sha1:OQn8VrGl8SS+b7GdfJpNlmL5yHk= Xref: reader01.eternal-september.org comp.lang.ada:55350 Date: 2019-01-23T15:47:05-08:00 List-Id: "Randy Brukardt" writes: > "Simon Wright" wrote in message > news:lyzhrruww2.fsf@pushface.org... > ... >> As Karl Müller 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 Will write code for food. void Void(void) { Void(); } /* The recursive call of the void */