comp.lang.ada
 help / color / mirror / Atom feed
* Misaligned address error
@ 2007-09-07 21:05 shaunpatterson
  2007-09-07 21:41 ` Adam Beneschan
  2007-09-07 21:49 ` Simon Wright
  0 siblings, 2 replies; 4+ messages in thread
From: shaunpatterson @ 2007-09-07 21:05 UTC (permalink / raw)


i'm working with some really old legacy code that seemed to be working
fine with gnat pro 3.16a1.  However, we decided to upgrade to gnat
5.

Everything built fine - however, I'm getting a misaligned address
value error at runtime:

raised PROGRAM_ERROR : data_reader.2.ada:109 misaligned address
value

The code:

  subtype Data_Type is Character;

  type Data_Type_Array is array (Natural range <>) of Data_Type;

  Data_String : Data_Type_Array (1 .. 8) := (others => Data_Type
(Ascii.Nul));
  for Data_String'Alignment use 4;
  for Data_String'Size use 8 * Data_Type'Size;
  -- global data buffer for reading and writing to file

  -- quick conversion variables
  One_Byte_Number : One_Byte_Number_Type;
  for One_Byte_Number'Address use Data_String'Address;

  Two_Byte_Number : Two_Byte_Number_Type;
  for Two_Byte_Number'Address use Data_String'Address;

  Four_Byte_Number : Four_Byte_Number_Type;
  for Four_Byte_Number'Address use Data_String'Address;

  Four_Byte_Signed_Number : Four_Byte_Signed_Number_Type;
  for Four_Byte_Signed_Number'Address use Data_String'Address;

  Four_Byte_Float : Float_Type;
  for Four_Byte_Float'Address use Data_String'Address;

  Eight_Byte_Float : Long_Float_Type;
  for Eight_Byte_Float'Address use Data_String'Address;  --- FAILS ON
THIS LINE ---


Could anyone help me make sense of this exception?

thanks
--
Shaun




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Misaligned address error
  2007-09-07 21:05 Misaligned address error shaunpatterson
@ 2007-09-07 21:41 ` Adam Beneschan
  2007-09-07 21:49 ` Simon Wright
  1 sibling, 0 replies; 4+ messages in thread
From: Adam Beneschan @ 2007-09-07 21:41 UTC (permalink / raw)


On Sep 7, 2:05 pm, shaunpatter...@gmail.com wrote:
> i'm working with some really old legacy code that seemed to be working
> fine with gnat pro 3.16a1.  However, we decided to upgrade to gnat
> 5.
>
> Everything built fine - however, I'm getting a misaligned address
> value error at runtime:
>
> raised PROGRAM_ERROR : data_reader.2.ada:109 misaligned address
> value
>
> The code:
>
>   subtype Data_Type is Character;
>
>   type Data_Type_Array is array (Natural range <>) of Data_Type;
>
>   Data_String : Data_Type_Array (1 .. 8) := (others => Data_Type
> (Ascii.Nul));
>   for Data_String'Alignment use 4;
>   for Data_String'Size use 8 * Data_Type'Size;
>   -- global data buffer for reading and writing to file
>
>   -- quick conversion variables
>   One_Byte_Number : One_Byte_Number_Type;
>   for One_Byte_Number'Address use Data_String'Address;
>
>   Two_Byte_Number : Two_Byte_Number_Type;
>   for Two_Byte_Number'Address use Data_String'Address;
>
>   Four_Byte_Number : Four_Byte_Number_Type;
>   for Four_Byte_Number'Address use Data_String'Address;
>
>   Four_Byte_Signed_Number : Four_Byte_Signed_Number_Type;
>   for Four_Byte_Signed_Number'Address use Data_String'Address;
>
>   Four_Byte_Float : Float_Type;
>   for Four_Byte_Float'Address use Data_String'Address;
>
>   Eight_Byte_Float : Long_Float_Type;
>   for Eight_Byte_Float'Address use Data_String'Address;  --- FAILS ON
> THIS LINE ---
>
> Could anyone help me make sense of this exception?

I don't know what a Long_Float_Type is.  What is it, and more
importantly, what is Long_Float_Type'Alignment?  Since
Data_String'Alignment is 4, Data_String can be located on any address
that is a multiple of 4 bytes (I assume you're compiling for a byte-
addressable machine); if it got located on an address that is a
multiple of 4 but not a multiple of 8, and if
Long_Float_Type'Alignment is 8, then the address clause can't be
honored properly.  (RM 13.3(27) says program execution is erroneous in
this case; GNAT has decided to make this raise a Program_Error at
runtime.)  If Long_Float_Type'Alignment is indeed 8, then you should
change Data_String'Alignment to 8 also, to make sure that Data_String
will be on an 8-byte boundary.  (P.S. I don't know GNAT well enough to
know whether that will succeed; not all Alignment clauses have to be
supported.)

(Apologies if this is a duplicate post.  Google is acting up, yet
again.)

Hope this helps,

                    -- Adam




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Misaligned address error
  2007-09-07 21:05 Misaligned address error shaunpatterson
  2007-09-07 21:41 ` Adam Beneschan
@ 2007-09-07 21:49 ` Simon Wright
  2007-09-07 22:52   ` Simon Wright
  1 sibling, 1 reply; 4+ messages in thread
From: Simon Wright @ 2007-09-07 21:49 UTC (permalink / raw)


shaunpatterson@gmail.com writes:

> i'm working with some really old legacy code that seemed to be
> working fine with gnat pro 3.16a1.  However, we decided to upgrade
> to gnat 5.

Not GNAT 6?

> Everything built fine - however, I'm getting a misaligned address
> value error at runtime:
>
> raised PROGRAM_ERROR : data_reader.2.ada:109 misaligned address
> value
>
>   Data_String : Data_Type_Array (1 .. 8) := (others => Data_Type
> (Ascii.Nul));
>   for Data_String'Alignment use 4;

>   Eight_Byte_Float : Long_Float_Type;
>   for Eight_Byte_Float'Address use Data_String'Address;  --- FAILS ON
> THIS LINE ---

I would guess that Eight_Byte_Float'Alignment needs to be 8 on your
machine? As I remember, a PowerPC has a maximum alignment requirement
of 4, an x86 8.

You could try saying

  for Data_String'Alignment use Long_Float_Type'Alignment;

if the compiler will let you. Other than that, there is an attribute
(possibly GNAT-special) which tells you the maximum alignment required
by the processor.



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Misaligned address error
  2007-09-07 21:49 ` Simon Wright
@ 2007-09-07 22:52   ` Simon Wright
  0 siblings, 0 replies; 4+ messages in thread
From: Simon Wright @ 2007-09-07 22:52 UTC (permalink / raw)


Simon Wright <simon.j.wright@mac.com> writes:

> there is an attribute (possibly GNAT-special) which tells you the
> maximum alignment required by the processor

Standard'Maximum_Alignment (Standard is the only permissible prefix)
provides the maximum useful alignment value for the target. This is a
static value that can be used to specify the alignment for an object,
guaranteeing that it is properly aligned in all cases.



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-09-07 22:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-09-07 21:05 Misaligned address error shaunpatterson
2007-09-07 21:41 ` Adam Beneschan
2007-09-07 21:49 ` Simon Wright
2007-09-07 22:52   ` Simon Wright

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