comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey Creem" <jeff@thecreems.com>
Subject: Re: Porting from Modula-2 to Ada
Date: Fri, 18 Oct 2002 10:55:33 GMT
Date: 2002-10-18T10:55:33+00:00	[thread overview]
Message-ID: <FMRr9.86812$Fz.263212@rwcrnsc51.ops.asp.att.net> (raw)
In-Reply-To: slrnaqvosa.nv.lutz@taranis.iks-jena.de

I'd probably go with a generic that can be instantiated for each "thing" you
want to
write or use a ugly 'address and 'size based approach that does not require
generics.
Note that if you take the generic route it is a little more work but
somewhat cleaner.

When I have done this I tend to make the generic formal parameter be private
instead
of limited private. There are times when limited might be right but almost
any time
someone makes something limited, the in memory representation one would get
via the
type is somewhat bogus.

Also, it is worth checking in the generic body that the 'size of the type is
a multiple of
the 'size of the storage element (or whatever type you use to write to the
file)

"Lutz Donnerhacke" <lutz@iks-jena.de> wrote in message
news:slrnaqvosa.nv.lutz@taranis.iks-jena.de...
> * Bernd Specht wrote:
> > Would it be an idea not to substitute the procedure by _one_ other
> > procedure but with a set of overloaded procedures?
> >
> > procedure Xxx (raw : Integer_Field) is ...
> > procedure Xxx (raw : Character_Field) is ...
> > procedure Xxx (raw : Float_Field) is ...
>
> And now use generics:
>
> generic
>   type T(<>) is limited private;
> procedure Xxx (data : T);
>
> procedure Xxx (data : T) is
>   use System.Storage_Elements;
>   raw : Storage_Array (Storage_Offset'First ..
>         Storage_Offset'First + (data'Size + Storage_Unit - 1) /
Storage_Unit);
>   pragma Import (Ada, raw);
>   for raw'Address use data'Address;
> begin
>   ...





  reply	other threads:[~2002-10-18 10:55 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-10-18  8:24 Porting from Modula-2 to Ada Manuel Collado
2002-10-18  9:45 ` Bernd Specht
2002-10-18 10:33   ` Lutz Donnerhacke
2002-10-18 10:55     ` Jeffrey Creem [this message]
2002-10-18 11:21       ` Lutz Donnerhacke
2002-10-18 22:01         ` Jeffrey Creem
2002-10-18 21:29     ` Jeffrey Carter
2002-10-18 21:39       ` Jeffrey Carter
2002-10-18 11:20 ` Nicolas Cailín Paul Gloster
2002-10-18 15:14   ` Pat Rogers
2002-10-24 14:51     ` Colin Paul Gloster
2002-10-25  3:43       ` Dennis Lee Bieber
2003-02-04 14:12       ` Colin Paul Gloster
2003-02-09  6:07         ` Robert I. Eachus
2002-10-19 13:30 ` SteveD
2002-10-22  7:48   ` Manuel Collado
2002-10-22  7:55 ` Manuel Collado
2002-10-22 18:56   ` Jeffrey Carter
2002-10-23  9:08     ` Manuel Collado
replies disabled

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