comp.lang.ada
 help / color / mirror / Atom feed
From: Nick Roberts <nick.roberts@acm.org>
Subject: Re: Object with zero bits
Date: Wed, 13 Oct 2004 15:59:51 +0100
Date: 2004-10-13T15:59:51+01:00	[thread overview]
Message-ID: <2t4u78F1pl10vU1@uni-berlin.de> (raw)
In-Reply-To: <mailman.299.1097648124.390.comp.lang.ada@ada-france.org>

Robert C. Leif wrote:

>    For the Ada implementation of the binary data part of CytometryML,
> I am using a discriminant to control a variant record where I need to
> store an object with a zero storage size.  Instead of null, I would
> like a record with an object of 0 bits (Empty_Var).

Why? (I guess the answer is to do with automated code generation.)

> I have about 12 parameters and would like to be able to have the user
> determine which ones he or she will store.

Do you mean as components of one record type?

>    If all else fails, I can make a Boolean type that corresponds to
> one bit in a 32 bit unsigned integer and simply consider this 32 bit
> unsigned integer as excess baggage.. 

An array of Booleans could be packed (one bit each). You could probably
squeeze 12 Booleans into a 16-bit array, and I think this would be
highly portable. In fact, I think you would get away with squeezing
such an array into 12 bits as a record (discriminant) component, on
most compilers.

>    I do have the luxury that I can wait for Ada 2005. Will this
> capacity be in Ada 2005? If so, is there an example?

If you are referring to the ability to declare an object (component) of
(genuinely) size 0, I don't think Ada 2005 is going to require compilers
to support this, and I'm afraid you will have to expect many compilers
not to. Most do not now (I've just tested GNAT, and it doesn't). As it
happens, I intend to enable ECLAT to support zero size objects for most
or all targets.

>    Another approach, which I am trying to avoid is to store the data
> as a stream that contains different data-types.

Why are you trying to avoid it?  I suggest streams might be a (nearly)
ideal solution. A custom Write procedure could be used to write out only
the components which the user wishes to store, and a custom Input
function could read the components which have been stored, and perhaps
initialise the ones which have not. I'd be happy to illustrate this
technique, if you wish.

-- 
Nick Roberts



  reply	other threads:[~2004-10-13 14:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-13  6:15 Object with zero bits Robert C. Leif
2004-10-13 14:59 ` Nick Roberts [this message]
2004-10-13 15:18 ` Wojtek Narczynski
     [not found]   ` <ckjns1$342$1@a1-hrz.uni-duisburg.de>
     [not found]     ` <2t5jo2F1s56mgU1@uni-berlin.de>
2004-10-14  0:47       ` Georg Bauhaus
2004-10-14  2:14         ` Nick Roberts
2004-10-14 14:55           ` Georg Bauhaus
2004-10-14  8:13     ` Martin Krischik
replies disabled

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