comp.lang.ada
 help / color / mirror / Atom feed
From: James Rhodes <james.rhodes@gecm.com>
Subject: Re: -ve values in enumeration rep clauses.
Date: 1996/06/14
Date: 1996-06-14T00:00:00+00:00	[thread overview]
Message-ID: <4prd9a$muh@gcsin3.geccs.gecm.com> (raw)
In-Reply-To: 5c3p6DALoKwxEwb0@djcull.demon.co.uk


Darel Cullen <Darel@djcull.demon.co.uk.demon.co.uk> 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.





  parent reply	other threads:[~1996-06-14  0:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-06-14  0:00 -ve values in enumeration rep clauses Darel Cullen
1996-06-14  0:00 ` Pascal Ledru
1996-06-14  0:00 ` Adam Beneschan
1996-06-14  0:00 ` James Rhodes [this message]
1996-06-15  0:00   ` Robert Dewar
replies disabled

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