comp.lang.ada
 help / color / mirror / Atom feed
From: Kilgallen@eisner.decus.org.nospam (Larry Kilgallen)
Subject: Variable sizes for record fields (was: C-style 'union' in Ada)
Date: 16 Aug 2001 22:18:19 -0500
Date: 2001-08-16T22:18:19-05:00	[thread overview]
Message-ID: <tIN5IMXgreuw@eisner.encompasserve.org> (raw)
In-Reply-To: WUXe7.15629$ZM2.1376965@newsread2.prod.itd.earthlink.net

In article <WUXe7.15629$ZM2.1376965@newsread2.prod.itd.earthlink.net>, David Brown <davidb@davidb.org> writes:
> Ted Dennison <dennison@telepath.com> wrote:
>> In article <9l7qon$d78$1@nntp9.atl.mindspring.net>, Brian Catlin says...
>>>
>>>I'm still trying to get both lobes around the Ada paradigm.  I have a
>>>record that I want to hold a pointer to a buffer which is either a String
>>>or Wide_String, but I don't want to statically declare which, so using a
>>>variant record won't work (at least given my understanding).  Likewise, I
>>>don't want to have two record definitions, one for String, and one for
>>>Wide_String.  In the package I'm designing, I don't care whether it is a
>>>String or Wide_String, I will just pass it to the file I/O packages
>>>(stream, in this case).  In C, I would:
> 
>> Thirdly, if I *did* have to have something like this for some reason
>> (which right now I cannot fathom), I'd probably define two structures (no
>> more or less work than defining one structure with both of them in it),
>> and use pointer-based unchecked_conversion to change my view of the
>> buffer between them. But its more likely I'd find a way to structurally
>> arrange things so that I didn't need to do that...
> 
> I have recently encountered a concrete example of the need for something
> like this.  The application is storing variable sized data fields in fixed
> length records (say disk sectors).  The block is defined as a large string.
> The beginning of the block contains lengths for each of the variable sized
> fields.  The data items start at the end of the record and work their way
> backward.

This sounds to me like the beginning of the record definition is the
discriminant values and the end of the record is the text fields.
The one trick, to achieve a fixed size, is to have an extra discriminant
to define the size of the "middle".  This is based on my experience with
Ada83.  Perhaps Ada95 lets you do more "math" with discriminant values
to avoid the need for an extra discriminant.



  parent reply	other threads:[~2001-08-17  3:18 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-08-13  6:06 C-style 'union' in Ada? Brian Catlin
2001-08-13  7:34 ` tmoran
2001-08-14  3:09 ` DuckE
2001-08-14  3:49   ` Brian Catlin
2001-08-14  7:37     ` Martin Dowie
2001-08-14  9:39       ` Ole-Hjalmar Kristensen
2001-08-14 11:49         ` Martin Dowie
2001-08-14 13:38 ` Ted Dennison
2001-08-16 22:35   ` David Brown
2001-08-17  3:14     ` Brian Catlin
2001-08-17 14:44       ` Ted Dennison
2001-08-17 16:38         ` Jeffrey Carter
2001-08-17 18:17           ` Ted Dennison
2001-08-17 18:45         ` Samuel T. Harris
2001-08-17  3:18     ` Larry Kilgallen [this message]
2001-08-17  6:34       ` Variable sizes for record fields David Brown
2001-08-17 10:44         ` Larry Kilgallen
2001-08-17 19:18           ` Warren W. Gay VE3WWG
2001-08-17 21:36             ` Ken Burtch
replies disabled

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