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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!m38g2000yqh.googlegroups.com!not-for-mail From: okellogg Newsgroups: comp.lang.ada Subject: Re: Generalized serialization for enumeration types Date: Wed, 26 Aug 2009 05:03:55 -0700 (PDT) Organization: http://groups.google.com Message-ID: <223e58cf-97d2-4db6-aa26-a5dc0d2b5056@m38g2000yqh.googlegroups.com> References: <249a69e5-8e21-4968-a183-64732618660a@h21g2000yqa.googlegroups.com> <54f0af10-4029-4209-84c4-163e3dcd56a9@r42g2000yqj.googlegroups.com> <2b55b138-5827-480c-8095-256ad1b7e205@e27g2000yqm.googlegroups.com> NNTP-Posting-Host: 80.156.47.202 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1251288236 30441 127.0.0.1 (26 Aug 2009 12:03:56 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 26 Aug 2009 12:03:56 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: m38g2000yqh.googlegroups.com; posting-host=80.156.47.202; posting-account=a23u_AkAAAB-Xz81hSqodYsmJRrMwioK User-Agent: G2/1.0 X-HTTP-Via: 1.1 DEIPROXY02, 1.1 INETPROXY02 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; UL611072003NET),gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:7989 Date: 2009-08-26T05:03:55-07:00 List-Id: On 26 Aug., 13:33, xorque wrote: > On Aug 26, 11:00=A0am, okellogg wrote: > > > If your enums are represented as you describe then why do you need > > representations? > > You could rely on the natural Ada representation (which happens to > > conform with your encoding rules as far as the enum values are > > concerned). > > Erm. Where in the (2005) RM does it state that enums are encoded > at big-endian 32 bit integers? > Perhaps I am misunderstanding - I thought along following lines: -- file: enum_to_big_endian_unsigned32.ads with Interfaces; generic type Enum_Type is (<>); function Enum_To_Big_Endian_Unsigned32 (Value : Enum_Type) return Interfaces.Unsigned_32; -- file: enum_to_big_endian_unsigned32.adb function Enum_To_Big_Endian_Unsigned32 (Value : Enum_Type) return Interfaces.Unsigned_32 is function htonl (host_int : Interfaces.Unsigned_32) return Interfaces.Unsigned_32; pragma Import (C, htonl, "htonl"); begin return htonl (Enum_Type'Pos (Value)); end Enum_To_Big_Endian_Unsigned32; -- file: enum2u32_test.adb - Test Main Program with Interfaces; with Enum_To_Big_Endian_Unsigned32; procedure Enum2U32_Test is type Color_T is (Red, Green, Blue); function To_U32 is new Enum_To_Big_Endian_Unsigned32 (Color_T); Result : Interfaces.Unsigned_32 :=3D To_U32 (Green); begin -- application code ... null; end;