comp.lang.ada
 help / color / mirror / Atom feed
From: Adrian Hoe <byhoe@my-deja.com>
Subject: Re: Help: Storage size
Date: 1999/07/16
Date: 1999-07-16T00:00:00+00:00	[thread overview]
Message-ID: <7mmf9f$5le$1@nnrp1.deja.com> (raw)
In-Reply-To: 7mfs92$jch@hobbes.crc.com

In article <7mfs92$jch@hobbes.crc.com>,
  "David C. Hoos, Sr." <david.c.hoos.sr@ada95.com> wrote:
>
> If you want to be assured that your types have the correct size,
> then I would not recommend basing your types on
> Interfaces.C.Unsigned_Short, because that type is dependent on the
size
> of C's unsigned short type for that platform.
>
> How about starting from scratch -- e.g.:
>
>    type Card8 is mod 2 ** 8;
>    for Card8'size use 8;
>    type Card16 is mod 2 ** 16;
>    for Card16'size use 16;
>
>    type Treq is record
>       ReqType : Card8;
>       Length  : Card16;
>    end record;
>
>    for Treq use record
>       ReqType at 0 range 0 .. 7;
>       Length  at 2 range 0 .. 15;
>    end record;
>
>    for Treq'size use 32;
>
> Note that there is one byte of unocupied space between the
> record components, consistent with the way gcc lays out
> your struct, in the absence of #pragma pack.


In case of the above implementation, how can one determine  the one
unoccupied byte between the two record components? Is this compiler or
platform dependable? In such cases, what will happen to the following
implementation:

   type Card8 is mod 2 ** 8;
   for Card8'size use 8;
   type Card16 is mod 2 ** 16;
   for Card16'size use 16;

   type Int32 is range -2 ** 31 .. (2 ** 31) - 1;
   for Int32'Size use 32;
   subtype Long is Int32;

   type Float64 is digits 15;
   subtype Long_Flt is Float64;

   Word_Size : constant POSITIVE := Long'Size / 8;

   type TReq is
      record
         ReqType  : Card8;
         Length   : Card16;
         Distance : Long_Flt;
      end record;

   for TReq use
      record
         ReqType  at 0 * Word_Size     range 0 .. 7;
         Length   at 0 * Word_Size + 2 range 0 .. 15
         Distance at 2 * Word_Size     range 0 .. 63;
      end record;


There will be one unoccupied byte between ReqType and Length and 4
unoccupied byte between Length and Distance. The record will be padded
to 32-bit spaces. Is this correct?

If Yes, is this portable to 64-bit platform such as UltraSPARC? Or in
the case of UltraSPARC, the record will be padded to 64-bit space?
--
Adrian BY, Hoe
--------------


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.




  parent reply	other threads:[~1999-07-16  0:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-07-13  0:00 Help: Storage size Adrian Hoe
1999-07-13  0:00 ` David C. Hoos, Sr.
1999-07-13  0:00   ` Adrian Hoe
1999-07-13  0:00     ` David C. Hoos, Sr.
1999-07-14  0:00       ` Adrian Hoe
1999-07-14  0:00         ` Simon Wright
1999-07-16  0:00           ` Adrian Hoe
1999-07-16  0:00       ` Adrian Hoe [this message]
1999-07-14  0:00     ` Keith Thompson
replies disabled

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