comp.lang.ada
 help / color / mirror / Atom feed
From: Georg Bauhaus <rm.tsoh.plus-bug.bauhaus@maps.futureapps.de>
Subject: Re: Ada Gems in educational material
Date: Thu, 06 Mar 2008 11:32:37 +0100
Date: 2008-03-06T11:32:37+01:00	[thread overview]
Message-ID: <47cfc845$0$21930$9b4e6d93@newsspool2.arcor-online.net> (raw)
In-Reply-To: <f34a2d2c-879c-415c-ba4e-657195c92c34@34g2000hsz.googlegroups.com>

Jerry wrote:
> On Mar 5, 8:48 am, Georg Bauhaus <rm.tsoh-plus.nicif-
> bauh...@maps.futureapps.de> wrote:
>> Gem #27: Changing Data Representation (Part 1) by Robert Dewar
>> explains how to use type derivation if you want to have two
>> representations of the same data. The types let you convert
>> between an external and an internal representation, say.
>>
>> http://www.adacore.com/2008/03/03/gem-27/
> 
> I wonder if this works on records with discriminants.

It should work I think, according to LRM 13.5.1 and
3.2.1(6). This works with GNAT. -gnatR2[s] might be useful.

package News5 is

   -- components
   type C is range 1000 .. 5000;

   -- discriminating values
   type T is range -1 .. +1;

   -- internal type
   type R(D: T) is record
      Data: C;
   end record;

   -- external type
   type X(D: T) is new R(D);
   for X'Size use 36;
   for X use record
      Data at 0 range 0 .. 11;
      D at 0 range 24 .. 27;
   end record;


   Internal: R := R'(0, Data => 4200);
   External: X := X(Internal);

end News5;



  parent reply	other threads:[~2008-03-06 10:32 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-05 15:48 Ada Gems in educational material Georg Bauhaus
2008-03-06  5:35 ` Jerry
2008-03-06  9:49   ` Peter Hermann
2008-03-06 10:32   ` Georg Bauhaus [this message]
2008-03-08  5:50   ` ME
replies disabled

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