* Re: Problem with representation clause
1997-12-08 0:00 Problem with representation clause Fabrizio Castrotorres
@ 1997-12-08 0:00 ` Jeff
1997-12-09 0:00 ` David C. Hoos, Sr.
1997-12-08 0:00 ` Matthew Heaney
` (2 subsequent siblings)
3 siblings, 1 reply; 7+ messages in thread
From: Jeff @ 1997-12-08 0:00 UTC (permalink / raw)
Fabrizio Castrotorres wrote:
> type Measurement_Status_Value is range -2 .. 1;
> for Measurement_Status_Value'Size use 2;
>
> type Slot_Number is range 0 .. 23;
>
> type Integrity_Data is array (Slot_Number) of Measurement_Status_Value;
> For Integrity_Data'Size use 24*2; -- REPRESENTATION 1
> pragma Pack(Integrity_Data);
>
> type Global_Integrity_Array is array( Slot_Number ) of Integrity_Data;
> For Global_Integrity_Array'Size use 24*48; -- REPRESENTATION 2
> pragma Pack(Global_Integrity_Array);
>
> [snip]
>
> size for "Global_Integrity_Array" too small, minimun allowed is 1536
>
> The size I specified is 24*(24*2) = 1152 bits
> The size the compiler requires is 24*(32*2) = 1536 bits
>
You are running into an 8-bit alignment problem with your first
array declaration. The compiler is assigning each element of the
array as an 8-bit quanity. Right off hand, I cannot think of a
quick fix. If this is a hardware interface, I would redefine the
declarations to access the status 8 bits at a time.
Jeff
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\ Jeff Rooze - http://www.treknet.net/~jrooze - balderon@bigfoot.com /
/ If builders built buildings the way some programmers write \
\ programs, then the first woodpecker that came along would destroy /
/ civilization. GERALD WEINBERG \
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Problem with representation clause
1997-12-08 0:00 ` Jeff
@ 1997-12-09 0:00 ` David C. Hoos, Sr.
0 siblings, 0 replies; 7+ messages in thread
From: David C. Hoos, Sr. @ 1997-12-09 0:00 UTC (permalink / raw)
Jeff wrote in message <348CE883.1CEC@bigfoot.com>...
>Fabrizio Castrotorres wrote:
> You are running into an 8-bit alignment problem with your first
> array declaration. The compiler is assigning each element of the
> array as an 8-bit quanity. Right off hand, I cannot think of a
> quick fix. If this is a hardware interface, I would redefine the
> declarations to access the status 8 bits at a time.
Jeff's answer is absolutely wrong: the declaration
type Global_Integrity_Array_2 is array( Slot_Number, Slot_Number ) of
Measurement_Status_Value;
pragma Pack(Global_Integrity_Array_2);
yields a size of 1152 bits.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Problem with representation clause
1997-12-08 0:00 Problem with representation clause Fabrizio Castrotorres
1997-12-08 0:00 ` Jeff
@ 1997-12-08 0:00 ` Matthew Heaney
1997-12-09 0:00 ` David C. Hoos, Sr.
1997-12-09 0:00 ` David C. Hoos, Sr.
1997-12-10 0:00 ` Aaro Koskinen
3 siblings, 1 reply; 7+ messages in thread
From: Matthew Heaney @ 1997-12-08 0:00 UTC (permalink / raw)
In article <66gvas$pmp@remus.rutgers.edu>, castroto@remus.rutgers.edu
(Fabrizio Castrotorres) wrote:
Try adding the Component_Size attribute too.
> type Measurement_Status_Value is range -2 .. 1;
> for Measurement_Status_Value'Size use 2;
>
> type Slot_Number is range 0 .. 23;
>
> type Integrity_Data is array (Slot_Number) of Measurement_Status_Value;
for Integrity_Data'Component_Size use 2;
> For Integrity_Data'Size use 24*2; -- REPRESENTATION 1
> pragma Pack(Integrity_Data);
> type Global_Integrity_Array is array( Slot_Number ) of Integrity_Data;
for Global_Integrity_Array'Component_Size use 24 * 2;
> For Global_Integrity_Array'Size use 24*48; -- REPRESENTATION 2
> pragma Pack(Global_Integrity_Array);
>The GNAT ADA 95 compiler (the one with the graphical user interface for NT/95)
>lets th file compile fine. The problem comes when I try to build the main
>module which uses this package specification (no body). It
>gives me the following error message:
>
>size for "Global_Integrity_Array" too small, minimun allowed is 1536
>
>
>The size I specified is 24*(24*2) = 1152 bits
>The size the compiler requires is 24*(32*2) = 1536 bits
>
>Is there a pragma I overlooked, specification I can write/correct, or command
>line switch I need, in order to fix this ?
You have to use both pragma Pack and T'Component_Size. See RM95 13.2 (9),
AARM 95 13.3 (52.c), AARM 95 13.3 (53, 53.a), and in particular AARM 95
13.3 (73, 73.a).
--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
<mailto:matthew_heaney@acm.org>
(818) 985-1271
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Problem with representation clause
1997-12-08 0:00 ` Matthew Heaney
@ 1997-12-09 0:00 ` David C. Hoos, Sr.
0 siblings, 0 replies; 7+ messages in thread
From: David C. Hoos, Sr. @ 1997-12-09 0:00 UTC (permalink / raw)
Matthew Heaney wrote in message ...
>In article <66gvas$pmp@remus.rutgers.edu>, castroto@remus.rutgers.edu
>(Fabrizio Castrotorres) wrote:
>
>Try adding the Component_Size attribute too.
>
The Component_Size attribute makes no difference in the resulting size;
The implementation advice of the Ada95 LRM 13.3(73) says
An implementation should support specified Component_Sizes that are factors
and multiples of the word size. For such Component_Sizes, the array should
contain no gaps between components. For other Component_Sizes (if
supported), the array should contain no gaps between components when packing
is also specified; the implementation should forbid this combination in
cases where it cannot support a no-gaps representation.
Perhaps the operative words here are "advice" and "should"
At any rate, a two dimensional array declared as
type Global_Integrity_Array_2 is array( Slot_Number, Slot_Number ) of
Measurement_Status_Value;
pragma Pack(Global_Integrity_Array_2);
yields a size of 1152 bits with gnat-3.10p
David C. Hoos, Sr.
david.c.hoos.sr@ada95.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Problem with representation clause
1997-12-08 0:00 Problem with representation clause Fabrizio Castrotorres
1997-12-08 0:00 ` Jeff
1997-12-08 0:00 ` Matthew Heaney
@ 1997-12-09 0:00 ` David C. Hoos, Sr.
1997-12-10 0:00 ` Aaro Koskinen
3 siblings, 0 replies; 7+ messages in thread
From: David C. Hoos, Sr. @ 1997-12-09 0:00 UTC (permalink / raw)
Hi
The problem would seem to be the implementation advice given in the Ada95
LRM
13.2(9), viz.:
For a packed array type, if the component subtype's Size is less than or
equal to the word size, and Component_Size is not specified for the type,
Component_Size should be less than or equal to the Size of the component
subtype, rounded up to the nearest factor of the word size.
So the solution would seem to be to use a two-dimensional array of your
two-bit components --
i.e. :
type Global_Integrity_Array_2 is array( Slot_Number, Slot_Number ) of
Measurement_Status_Value;
pragma Pack(Global_Integrity_Array_2);
The gnat compiler gives this array a size of 1152 bits.
Fabrizio Castrotorres wrote in message <66gvas$pmp@remus.rutgers.edu>...
>Hi,
>
>Given the code:
>-- START CODE
>
>
> type Measurement_Status_Value is range -2 .. 1;
> for Measurement_Status_Value'Size use 2;
>
> type Slot_Number is range 0 .. 23;
>
> type Integrity_Data is array (Slot_Number) of Measurement_Status_Value;
> For Integrity_Data'Size use 24*2; -- REPRESENTATION 1
> pragma Pack(Integrity_Data);
>
> type Global_Integrity_Array is array( Slot_Number ) of Integrity_Data;
> For Global_Integrity_Array'Size use 24*48; -- REPRESENTATION 2
> pragma Pack(Global_Integrity_Array);
>
>-- END CODE
>
>The GNAT ADA 95 compiler (the one with the graphical user interface for
NT/95)
>lets th file compile fine. The problem comes when I try to build the main
>module which uses this package specification (no body). It
>gives me the following error message:
>
>size for "Global_Integrity_Array" too small, minimun allowed is 1536
>
>
>The size I specified is 24*(24*2) = 1152 bits
>The size the compiler requires is 24*(32*2) = 1536 bits
>
>Is there a pragma I overlooked, specification I can write/correct, or
command
>line switch I need, in order to fix this ?
>
>Please reply to fcastrot@ccmail.avionics.itt.com
>
>Thanks
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Problem with representation clause
1997-12-08 0:00 Problem with representation clause Fabrizio Castrotorres
` (2 preceding siblings ...)
1997-12-09 0:00 ` David C. Hoos, Sr.
@ 1997-12-10 0:00 ` Aaro Koskinen
3 siblings, 0 replies; 7+ messages in thread
From: Aaro Koskinen @ 1997-12-10 0:00 UTC (permalink / raw)
castroto@remus.rutgers.edu (Fabrizio Castrotorres) writes:
> type Measurement_Status_Value is range -2 .. 1;
> for Measurement_Status_Value'Size use 2;
>
> type Slot_Number is range 0 .. 23;
>
> type Integrity_Data is array (Slot_Number) of Measurement_Status_Value;
> For Integrity_Data'Size use 24*2; -- REPRESENTATION 1
> pragma Pack(Integrity_Data);
>
> type Global_Integrity_Array is array( Slot_Number ) of Integrity_Data;
> For Global_Integrity_Array'Size use 24*48; -- REPRESENTATION 2
> pragma Pack(Global_Integrity_Array);
> The GNAT ADA 95 compiler (the one with the graphical user interface
> for NT/95) lets th file compile fine. The problem comes when I try
> to build the main module which uses this package specification (no
> body). It gives me the following error message:
>
> size for "Global_Integrity_Array" too small, minimun allowed is 1536
The suggestion to specify a two-dimensional array is probably the
nicest solution. However, I have found another solution, or more like
a hack/kludge, which works with GNAT (3.10p):
type Wrapper is record
ID : Integrity_Data;
end record;
for Wrapper use record
ID at 0 range 0 .. 47;
end record;
for Wrapper'size use 48;
type Global_Integrity_Array is array( Slot_Number ) of Wrapper;
For Global_Integrity_Array'Size use 24*48; -- REPRESENTATION 2
pragma Pack(Global_Integrity_Array);
This results in a 1152-bit array. I think this would be the only way
to it, if Integrity_Data were not an array...
--
Aaro Koskinen (aaro@iki.fi)
http://www.iki.fi/aaro/
^ permalink raw reply [flat|nested] 7+ messages in thread