comp.lang.ada
 help / color / mirror / Atom feed
From: "Martin Krischik" <Martin.Krischik@T-Online.de>
Subject: Re: Representing data differently
Date: Wed, 12 Feb 2003 19:52:27 +0100
Date: 2003-02-12T19:52:27+01:00	[thread overview]
Message-ID: <pan.2003.02.12.18.52.25.30761@T-Online.de> (raw)
In-Reply-To: 686be06c.0302070615.3943b629@posting.google.com

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




  parent reply	other threads:[~2003-02-12 18:52 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-07 14:15 Representing data differently Daniel Allex
2003-02-07 18:07 ` tmoran
2003-02-09  4:39   ` Craig Carey
2003-02-10 12:47     ` Colin Paul Gloster
2003-02-13 17:21       ` Craig Carey
2003-02-08  0:24 ` Wojtek Narczynski
2003-02-12 18:52 ` Martin Krischik [this message]
2003-02-22 19:09   ` Robert A Duff
2003-02-23 13:06     ` Martin Krischik
2003-02-23 21:09 ` Craig Carey
2003-02-23 21:59   ` tmoran
replies disabled

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