From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,72340e997bfd5289,start X-Google-Attributes: gid103376,public From: "James E. Hopper" Subject: array size Date: 1999/12/10 Message-ID: <101219991605504828%hopperj@macconnect.com>#1/1 X-Deja-AN: 559150241 Content-Transfer-Encoding: 8bit Organization: http://extra.newsguy.com Content-Type: text/plain; charset=ISO-8859-1 User-Agent: YA-NewsWatcher/4.2.3 Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 1999-12-10T00:00:00+00:00 List-Id: 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;