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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,8272e612db888282 X-Google-Attributes: gid103376,public From: James Rhodes Subject: Re: -ve values in enumeration rep clauses. Date: 1996/06/14 Message-ID: <4prd9a$muh@gcsin3.geccs.gecm.com>#1/1 X-Deja-AN: 160123643 references: <5c3p6DALoKwxEwb0@djcull.demon.co.uk> content-type: text/plain; charset=us-ascii organization: GEC-Marconi mime-version: 1.0 newsgroups: comp.lang.ada x-mailer: Mozilla 1.1N (Windows; I; 16bit) Date: 1996-06-14T00:00:00+00:00 List-Id: Darel Cullen wrote: >Hi, > Came across an interesting problem at work today. > >What happens if for example :- > >type A_Type is > ( A, B, C ); > >for A_Type use > ( > A => -1, > B => -2, > C => -3 > ); > >for A_Type'Size use 8; > Doesn't the ordering of the values have to match the ordering of the literals? i.e. the order of the integer values ( -1 , -2 , -3 ) is decreasing hence illegal, so change the order to ( -3 , -2 , -1 ) and change the enumerated values appropriately. As this is not what you asked, I'll not dwell on this. >Now - to be able to extract the -ve values via unchecked_conversion >from a byte proves impossible because the use 8 creates an unsigned >byte, so whats the best way to represent negative values from a >rep-claused enumerated type ? > Although I don't like using UNCHECKED_CONVERSION generally... you could try something this type MY_INT is new INTEGER range -128 .. 127; for MY_INT'size use 8; then instansiate and use UNCHECKED_CONVERSION in the usual way. your compiler may (or may not ) have a predifined INTEGER type ( such as SHORT_SHORT_INTEGER ) of this size already which you can use. You've not indicated what you are trying to do in more general terms so I'll not try to second guess you with different ideas. Have a nice day, James.