From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26474 invoked by alias); 2 Aug 2005 20:29:13 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 26461 invoked by uid 22791); 2 Aug 2005 20:29:10 -0000 Received: from sadr.equallogic.com (HELO sadr.equallogic.com) (66.155.203.134) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Tue, 02 Aug 2005 20:29:10 +0000 Received: from sadr.equallogic.com (localhost.localdomain [127.0.0.1]) by sadr.equallogic.com (8.12.8/8.12.8) with ESMTP id j72KT8Zd010729 for ; Tue, 2 Aug 2005 16:29:08 -0400 Received: from M31.equallogic.com (M31.equallogic.com [172.16.1.31]) by sadr.equallogic.com (8.12.8/8.12.8) with SMTP id j72KT8Nd010724; Tue, 2 Aug 2005 16:29:08 -0400 Received: from PKONING.equallogic.com ([172.16.1.186]) by M31.equallogic.com with Microsoft SMTPSVC(6.0.3790.211); Tue, 2 Aug 2005 16:29:08 -0400 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <17135.55187.360000.108661@gargle.gargle.HOWL> Date: Tue, 02 Aug 2005 20:29:00 -0000 From: Paul Koning To: sjackman@gmail.com Cc: dave.korn@artimi.com, gcc@sources.redhat.com Subject: Re: memcpy to an unaligned address References: <7f45d9390508021226ea16fc7@mail.gmail.com> <7f45d93905080213152a54106c@mail.gmail.com> X-SW-Source: 2005-08/txt/msg00082.txt.bz2 >>>>> "Shaun" == Shaun Jackman writes: >> 2) Is there padding between the struct members to maintain their >> natural alignments (on the assumption that the struct's base >> address is aligned.) Shaun> There is no padding. The structure is defined as Shaun> __attribute__((packed)) to explicitly remove the padding. The Shaun> result is that gcc knows the unaligned four byte member is at Shaun> an offset of two bytes from the base of the struct, but uses a Shaun> four byte load at the unaligned address of base+2. I don't Shaun> expect... Shaun> p-> unaligned = n; Shaun> ... to work, ... I would. If you tell gcc that a thing is unaligned, it is responsible for doing unaligned references to it. That very definitely includes direct references to the content in expressions. And in general that works. Clearly there is a GCC bug here; GCC put the field at an unaligned offset, but did not do unaligned references to it. paul