comp.lang.ada
 help / color / mirror / Atom feed
From: Kilgallen@eisner.decus.org.nospam (Larry Kilgallen)
Subject: Re: Variable sizes for record fields
Date: 17 Aug 2001 05:44:12 -0500
Date: 2001-08-17T05:44:12-05:00	[thread overview]
Message-ID: <8eI27ybFqL0Y@eisner.encompasserve.org> (raw)
In-Reply-To: NV2f7.16792$ZM2.1470093@newsread2.prod.itd.earthlink.net

In article <NV2f7.16792$ZM2.1470093@newsread2.prod.itd.earthlink.net>, David Brown <s-complangada@davidb.org> writes:
> Larry Kilgallen <Kilgallen@eisner.decus.org.nospam> wrote:
> 
>>> 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.
> 
> To make this work, I would need several things.  First of all, my
> discriminants would have to be an array of values whose size is based on
> another discriminant.

An Ada record type always has a fixed number of discriminants (often zero).

> Second, I need to represent things (like the size of the middle) without
> taking up any space.  They need to be computed and that's it.  The sizes of
> each of the other text strings needs to be based on the array of
> discriminant sizes.

Check into the Ada95 angle.

> Third, I need to be able to change the structure in-place.  It is
> complicated code, and I don't think that the compiler would understand all
> of the cases involved, even if you could arbitrarily assign to
> discriminants like this.

	POINTER_TO_NEW_RECORD := new MY_RECORD_TYPE (
		SIZE_1 => 42,
		SIZE 2 => 42,
		SIZE_3 => 42,
		SIZE_REST => 42 );

> I wasn't even able to make a simple record containing a discriminant and a
> string of that length and come up with a way to make the particular
> discriminant a constant and not take up any storage.

That is just the point.  Ada requires that the discriminants of the record
can be recognized at run time.  There is no way to do that without taking
up space.



  reply	other threads:[~2001-08-17 10:44 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     ` Variable sizes for record fields (was: C-style 'union' in Ada) Larry Kilgallen
2001-08-17  6:34       ` Variable sizes for record fields David Brown
2001-08-17 10:44         ` Larry Kilgallen [this message]
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