comp.lang.ada
 help / color / mirror / Atom feed
From: "James E. Hopper" <hopperj@macconnect.com>
Subject: array size
Date: 1999/12/10
Date: 1999-12-10T00:00:00+00:00	[thread overview]
Message-ID: <101219991605504828%hopperj@macconnect.com> (raw)

the following program is a cut and paste from some code we are porting
to gnat from vads.  if some reason the type

 type Day_Array_Type is array ( Day_Type ) of Preset_Array_Type;
  pragma pack (Day_Array_Type);  -- RAD SOLARIS PORT

is not packing the array how i would expect.  it appears to be padding
each element with 2 bytes to align array elements on word boundries
despite the pragma pack.  using rep spec doesnt help because compiler
spits it out as wrong size.

any ideas???

thansk jim

-----------------

with text_io;


procedure  test is

   type Integer_Type is range -32_768..32_767;
   for Integer_Type' Size use 16;
   --
   -- Integer_type will take the place of Standard Integer and it
   -- will be confined to 16 bits.
   --
    
   subtype Natural_Type is Integer_Type range  0..32_767;
   --
   -- Natural_type will take the place of Standard Natural and it
   -- will be confined to 16 bits.
   --

   subtype Positive_Type is Integer_Type range  1..32_767;
   --
   -- Positive_type will take the place of Standard Positive and it
   -- will be confined to 16 bits.
   --
  Byte_Size : constant Positive_Type := 8;

  type Frequency_Type is range 0..399975;
  for Frequency_Type' Size use 3 * Byte_Size;

  type Preset_Type is ( Pset20, Pset19, Pset18, Pset17, Pset16, Pset15
);
  type Preset_Array_Type is array ( Preset_Type ) of Frequency_Type;
  pragma pack (Preset_Array_Type);  -- RAD SOLARIS PORT
  for Preset_Array_Type'Size use 6 * Frequency_Type'Size;

  type Day_Type is ( Day1, Day2, Day3, Day4, Day5, Day6, Day7 );
  type Day_Array_Type is array ( Day_Type ) of Preset_Array_Type;
  pragma pack (Day_Array_Type);  -- RAD SOLARIS PORT
-- I had to comment out this next line to get my little test program to
compile, this
-- is straight from a real example.  For some reason the compiler
thinks Day_Array_Type
-- needs to be 1120 bits, even when I pack it.
-- Rick and I did a little calculating and the difference is 112, which
is 7 * 16,
-- or 2 extra bytes per array element.  If you take the 144 (size of
each elem) + 16,
-- gives you 160, or 5 words.  So, we're guessing the compiler is
lining up each 
-- array element on a word boundary (ie it seems to be ignoring my pack!
--  for Day_Array_Type'Size use 7 * 18 * Byte_Size;

-- We tried the following just for giggles but interestingly, the
compiler 
-- says that Preset_Array_Type'Size isn't static!!
--  for Day_Array_Type'Size use 7 * Preset_Array_Type'Size;

begin

text_io.put ("Size of Frequency Type = ");
text_io.put (integer'image (Frequency_Type'size));
text_io.new_line;
text_io.new_line;

text_io.put ("Length of Preset_Array_Type = ");
text_io.put (integer'image (Preset_Array_Type'Length));
text_io.new_line;
text_io.put ("Size of Preset array elems (Frequency_Type) * length of
array = ");
text_io.put (integer'image (Frequency_Type'Size *
Preset_Array_Type'Length));
text_io.new_line;
text_io.put ("Size of Preset_Array_Type (per compiler- should match
above calculation = ");
text_io.put (integer'image (Preset_Array_Type'size));
text_io.new_line;
text_io.new_line;

text_io.put ("Length of Day_Array_Type = ");
text_io.put (integer'image (Day_Array_Type'Length));
text_io.new_line;
text_io.put ("Size of day array elems (Preset_Array _Type) * length of
array = ");
text_io.put (integer'image (Preset_Array_Type'Size *
Day_Array_Type'Length));
text_io.new_line;
text_io.put ("Size of Day_Array_Type (per compiler- should match above
calculation = ");
text_io.put (integer'image (Day_Array_Type'size));
text_io.new_line;


end test;




             reply	other threads:[~1999-12-10  0:00 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-12-10  0:00 James E. Hopper [this message]
1999-12-10  0:00 ` array size Matthew Heaney
1999-12-11  0:00   ` Robert Dewar
1999-12-11  0:00     ` James E. Hopper
1999-12-12  0:00       ` Matthew Heaney
1999-12-11  0:00     ` Matthew Heaney
1999-12-13  0:00       ` Robert A Duff
1999-12-11  0:00     ` Robert A Duff
1999-12-11  0:00       ` Matthew Heaney
1999-12-11  0:00   ` James E. Hopper
1999-12-11  0:00 ` DuckE
1999-12-11  0:00   ` James E. Hopper
1999-12-11  0:00     ` DuckE
1999-12-12  0:00       ` James E. Hopper
1999-12-12  0:00       ` Matthew Heaney
replies disabled

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