* Object with zero bits @ 2004-10-13 6:15 Robert C. Leif 2004-10-13 14:59 ` Nick Roberts 2004-10-13 15:18 ` Wojtek Narczynski 0 siblings, 2 replies; 7+ messages in thread From: Robert C. Leif @ 2004-10-13 6:15 UTC (permalink / raw) To: comp.lang.ada 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). I have about 12 parameters and would like to be able to have the user determine which ones he or she will store. 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.. 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? type Fl_530_Rec_Type(Choice: Boolean) is record case Choice is when True => Part:Fl_530_Type := 0; --16 bit unsigned integer. when False => null; --Empty_Var:Empty_Type; end case; end record; Another approach, which I am trying to avoid is to store the data as a stream that contains different data-types. Thank you. Bob Leif ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Object with zero bits 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 1 sibling, 0 replies; 7+ messages in thread From: Nick Roberts @ 2004-10-13 14:59 UTC (permalink / raw) 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 ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Object with zero bits 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> 1 sibling, 1 reply; 7+ messages in thread From: Wojtek Narczynski @ 2004-10-13 15:18 UTC (permalink / raw) Hello, You can declare a record that will have zero bits size. Is this what you want? type Frame_Mark is null record; I saw this in System.Stack_Checking. Regards, Wojtek ^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <ckjns1$342$1@a1-hrz.uni-duisburg.de>]
[parent not found: <2t5jo2F1s56mgU1@uni-berlin.de>]
* Re: Object with zero bits [not found] ` <2t5jo2F1s56mgU1@uni-berlin.de> @ 2004-10-14 0:47 ` Georg Bauhaus 2004-10-14 2:14 ` Nick Roberts 0 siblings, 1 reply; 7+ messages in thread From: Georg Bauhaus @ 2004-10-14 0:47 UTC (permalink / raw) Nick Roberts <nick.roberts@acm.org> wrote: : Georg Bauhaus wrote: : :> : You can declare a record that will have zero bits size. Is this what :> : you want? :> : :> : type Frame_Mark is null record; :> :> And maybe add a rep clause, :> :> type Nothing_At_All is null record; :> for Nothing_At_All'size use 0; : : But many (perhaps most) compilers will make an object (or component) of : type (subtype) Nothing_At_All at least size 1 (one bit). An object of type Nothing_At_All can be 8 bits in size. But Nothing_At_All as a record component seems to vanish, type Num is limited record virt: Nothing_At_All := initialize_Num(Num'access); n: Natural; end record; pragma assert(Num'Max_Size_in_Storage_Elements = 4); With suitable rep clauses, Boolean discriminants don't seem to consume space in some variant records, when the compiler can find out :-) ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Object with zero bits 2004-10-14 0:47 ` Georg Bauhaus @ 2004-10-14 2:14 ` Nick Roberts 2004-10-14 14:55 ` Georg Bauhaus 0 siblings, 1 reply; 7+ messages in thread From: Nick Roberts @ 2004-10-14 2:14 UTC (permalink / raw) Georg Bauhaus wrote: > : But many (perhaps most) compilers will make an object (or component) of > : type (subtype) Nothing_At_All at least size 1 (one bit). > > An object of type Nothing_At_All can be 8 bits in size. > But Nothing_At_All as a record component seems to vanish, > > type Num is limited record > virt: Nothing_At_All := initialize_Num(Num'access); > n: Natural; > end record; > > pragma assert(Num'Max_Size_in_Storage_Elements = 4); > > 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. -- Nick Roberts ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Object with zero bits 2004-10-14 2:14 ` Nick Roberts @ 2004-10-14 14:55 ` Georg Bauhaus 0 siblings, 0 replies; 7+ messages in thread From: Georg Bauhaus @ 2004-10-14 14:55 UTC (permalink / raw) 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 ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Object with zero bits [not found] ` <ckjns1$342$1@a1-hrz.uni-duisburg.de> [not found] ` <2t5jo2F1s56mgU1@uni-berlin.de> @ 2004-10-14 8:13 ` Martin Krischik 1 sibling, 0 replies; 7+ messages in thread From: Martin Krischik @ 2004-10-14 8:13 UTC (permalink / raw) Georg Bauhaus wrote: > Wojtek Narczynski <wojtek@power.com.pl> wrote: > : Hello, > : > : You can declare a record that will have zero bits size. Is this what you > : want? > : > : type Frame_Mark is null record; > > And maybe add a rep clause, > > type Nothing_At_All is null record; > for Nothing_At_All'size use 0; That's for the type. If you actually use the type: X: Nothing_At_All; Y : aliased Nothing_At_All; then X'Size is could still be >0. And Y'Size must be >0 since Y need to have an unshared address to be aliased. Martin -- mailto://krischik@users.sourceforge.net http://www.ada.krischik.com ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2004-10-14 14:55 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 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 2004-10-14 8:13 ` Martin Krischik
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox