comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Misaligned address error
Date: Fri, 07 Sep 2007 14:41:27 -0700
Date: 2007-09-07T14:41:27-07:00	[thread overview]
Message-ID: <1189201287.806186.103630@w3g2000hsg.googlegroups.com> (raw)
In-Reply-To: <1189199157.591747.278390@r34g2000hsd.googlegroups.com>

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




  reply	other threads:[~2007-09-07 21:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-07 21:05 Misaligned address error shaunpatterson
2007-09-07 21:41 ` Adam Beneschan [this message]
2007-09-07 21:49 ` Simon Wright
2007-09-07 22:52   ` Simon Wright
replies disabled

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