From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24145 invoked by alias); 5 Nov 2002 17:16:04 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 24091 invoked by uid 71); 5 Nov 2002 17:16:02 -0000 Date: Tue, 05 Nov 2002 09:16:00 -0000 Message-ID: <20021105171602.24087.qmail@sources.redhat.com> To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, From: Andreas Schwab Subject: Re: c++/8464: Bus Error (SIGBUS) due to misaligned access Reply-To: Andreas Schwab X-SW-Source: 2002-11/txt/msg00238.txt.bz2 List-Id: The following reply was made to PR c++/8464; it has been noted by GNATS. From: Andreas Schwab 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."