From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 29 Jun 93 20:25:05 GMT From: rational.com!geneo@uunet.uu.net (Gene Ouye) Subject: Re: Retrieving Rep Spec'ed Enumeration Values Message-ID: <1993Jun29.202505.21816@rational.com> List-Id: Sandy Wise (sandy@beeker.cs.umass.edu) wrote: : In article <1993Jun28.205806.11601@wdl.loral.com> mab@dst17.wdl.loral.com (Ma rk A Biggar) writes: : In article I write: : >Suppose you had a type like so: : > type Color is ( Red, Green, Blue ); : > for Color use ( Red => 4, Green => 8, Blue => 16 ); : >I cannot seem to find a portable way to retrieve the values assigned : >in the rep-spec. Color'Pos is explicitly defined to be unaffected by : >the rep spec (LRM 13.3 paragraph 6). : The only protable way is to use Unchecked_conversion. : Yech! And not very portable. Makes assumptions about the size : and representation of enumeration types. Dave's previous post is correct about this, you don't need some special attribute to get the value assigned in the rep-clause. Assuming that you used a 'SIZE attribute to make the enumeration values take the same space as an integer, if you looked at My_Color : Color := Red; My_Integer : Integer := 4; Both storage locations would appear identical in memory. Of course the fact that you are using the predefined type Integer makes your code not portable (because Integer'Size can vary from one platform to another). :... : No it just needs to communicate with a very broken language... (C) : I need to be able to communicate enumeration types over a network : link. Transmitting them a string rep ('image) is expensive at both : ends of the link -- so the rational thing to do seemed to be set the : numeric representation (they are called ENUMERATION types, you know : :-) and send that! If you are talking over a heterogeneoust network to C programs, will all of your C programs view storage the same way? I'm not a C person, so I don't know if C "int"s (or whatever you're mapping your Ada Color type to in C) are the same in all environments. If they're not, you have some work to do. If they are the same, the use the 'SIZE attribute (see LRM 13.7.2(5)). : I have never seen an Ada program that required : emuneration rep specs, that really required the internal : representation to become visible in the program. I have, for exactly the following reason : They don't need to become visible in the program but are needed in the : external data representation code... : But, if you really really need it just declare an anonymous array to be : used for conversions: : internal_colors: array (Color) of integer := (4,8,16); : Ah ha! A portable solution! I knew you had it in you... :-) As mentioned above, this is not really portable. Gene Ouye (geneo@rational.com) (301) 897-4014