From: Georg Bauhaus <sb463ba@l1-hrz.uni-duisburg.de>
Subject: Re: Object with zero bits
Date: Thu, 14 Oct 2004 14:55:47 +0000 (UTC)
Date: 2004-10-14T14:55:47+00:00 [thread overview]
Message-ID: <ckm41j$rk0$1@a1-hrz.uni-duisburg.de> (raw)
In-Reply-To: 2t65nbF1s7981U1@uni-berlin.de
Nick Roberts <nick.roberts@acm.org> wrote:
:> With suitable rep clauses, Boolean discriminants don't seem to consume
:> space in some variant records, when the compiler can find out :-)
:
: Which compiler please? Would you be kind enough to post test code.
This "works" with ObjectAda:
package Test_02 is
type Representation is (As_S, As_V);
for Representation'Size use 1;
type String_Access is access String;
type Component (The_Representation : Representation) is
record
case The_Representation is
when As_S => The_S : String_Access;
when As_V => The_V : Natural;
end case;
end record;
for Component use record
--The_Representation at 4 range 0 .. 1; -- adds more bits
The_S at 0 range 0 .. 31;
The_V at 0 range 0..31;
end record;
OA_Component_Size: constant := 32;
pragma assert (Component'Size = OA_Component_Size);
generic
The_Representation: Representation;
package Nested is
type Item is
record
The_Component: Component(The_Representation);
end record;
end Nested;
package One_Or_Other is new Nested(As_V);
type V_Item is new One_Or_Other.Item;
pragma Assert(V_Item'Size = Component'Size);
pragma Assert(V_Item'Max_Size_In_Storage_Elements = 4);
Test: V_Item;
pragma Assert(Test.The_Component'Position = 0);
end Test_02;
(The original problem was to specify represenations for a record with
a component of type Component, which isn't possible because objects
of type component vary in size (by definition?). Deriving a new type,
type D is new T(value); where T has one discriminant
does not seem to "fix" the size.
-- georg
next prev parent reply other threads:[~2004-10-14 14:55 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
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 [this message]
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