This is the mail archive of the gcc-prs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: c++/8464: Bus Error (SIGBUS) due to misaligned access


The following reply was made to PR c++/8464; it has been noted by GNATS.

From: Andreas Schwab <schwab@suse.de>
To: kyle_s_hoyt@raytheon.com
Cc: gcc-gnats@gcc.gnu.org
Subject: Re: c++/8464: Bus Error (SIGBUS) due to misaligned access
Date: Tue, 05 Nov 2002 18:10:46 +0100

 kyle_s_hoyt@raytheon.com writes:
 
 |> typedef struct
 |> {
 |>   int message;
 |>   int numwords;
 |>   double latitude;
 |>   double longitude;
 |>   double altitude;
 |>   double ew_rate;
 |>   double ns_rate;
 |>   int time;
 |> } NAVIGATION_DATAS __attribute__ ((aligned(4)));
 |> 
 |> void ProcessNavData(NAVIGATION_DATAS *nav_ptr)
 |> {
 |>   NAVIGATION_DATAS store;
 |> 
 |>   store = *nav_ptr;
 |> }
 |> 
 |> int main()
 |> {
 |>   unsigned int data[1024];
 |> 
 |>   ProcessNavData((NAVIGATION_DATAS *)&data[0]);
 |>   ProcessNavData((NAVIGATION_DATAS *)&data[1]);
 |> }
 
 This is invoking undefined behavior.  The aligned attribute by itself
 cannot _decrease_ the alignment, only _increase_ it (ie. it specifies a
 minimum alignment).  You have to add packed as well.
 
 Andreas.
 
 -- 
 Andreas Schwab, SuSE Labs, schwab@suse.de
 SuSE Linux AG, Deutschherrnstr. 15-19, D-90429 Nürnberg
 Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
 "And now for something completely different."


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]