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-7-bit X-Google-Thread: 103376,bb6f4bd169077fb3 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-02-13 08:40:42 PST Path: archiver1.google.com!news2.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.vmunix.org!newsfeed01.sul.t-online.de!newsmm00.sul.t-online.com!t-online.de!news.t-online.com!not-for-mail From: "Martin Krischik" Newsgroups: comp.lang.ada Subject: Re: Representing data differently Date: Wed, 12 Feb 2003 19:52:27 +0100 Organization: never organized Message-ID: References: <686be06c.0302070615.3943b629@posting.google.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15 X-Trace: news.t-online.com 1045154297 03 21709 t7ngE1CVTdYq3l 030213 16:38:17 X-Complaints-To: abuse@t-online.com X-Sender: 05341395658-0001@t-dialin.net User-Agent: Pan/0.13.0 (The whole remains beautiful) Xref: archiver1.google.com comp.lang.ada:34060 Date: 2003-02-12T19:52:27+01:00 List-Id: On Fri, 07 Feb 2003 06:15:18 +0000, Daniel Allex wrote: > In C I can represent the same data multiple ways using structs and > unions. How and can I do this in Ada? See example below: > > // > // Example of C's representation clause > // > struct MT_37_header > { > short > :4, > nw:6, > mt:6; > short > :16; // place holder > short > :16; // place holder > short > :16; // place holder > }; Since it is quite dangerous you have to do a lot of typing: -- snip type State is record uninitialized : Boolean ; on : Boolean ; writeLineNumber : Boolean ; writePrefix : Boolean ; end record; for State use record uninitialized at 0 range 0..0; on at 0 range 1..1; writeLineNumber at 0 range 2..2; writePrefix at 0 range 3..3; end record; -- snap The first statement defines the record, the second defines the layout. Nothing stops you from placing two record elements at the same position. with regards Martin PS: If you like you can look at the rest of the (unfinished) source as well: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/adacl/adacl/Include/AdaCL-Trace.adb -- Martin Krischik mailto://Martin@krischik.com http://www.martin.krischik.com