From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21890 invoked by alias); 2 Aug 2005 19:13:36 -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 21806 invoked by uid 22791); 2 Aug 2005 19:13:29 -0000 Received: from rproxy.gmail.com (HELO rproxy.gmail.com) (64.233.170.192) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Tue, 02 Aug 2005 19:13:29 +0000 Received: by rproxy.gmail.com with SMTP id y7so1717231rne for ; Tue, 02 Aug 2005 12:13:27 -0700 (PDT) Received: by 10.11.118.19 with SMTP id q19mr73266cwc; Tue, 02 Aug 2005 12:13:27 -0700 (PDT) Received: by 10.11.99.15 with HTTP; Tue, 2 Aug 2005 12:13:27 -0700 (PDT) Message-ID: <7f45d93905080212136ecb0cbb@mail.gmail.com> Date: Tue, 02 Aug 2005 19:13:00 -0000 From: Shaun Jackman Reply-To: Shaun Jackman To: Dave Korn Subject: Re: memcpy to an unaligned address Cc: gcc@sources.redhat.com In-Reply-To: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <7f45d9390508021032aea5a61@mail.gmail.com> X-SW-Source: 2005-08/txt/msg00074.txt.bz2 On 8/2/05, Dave Korn wrote: > In order for anyone to answer your questions about the alignment of > various types in a struct, don't you think you should perhaps have told u= s a > little about what those types actually are and how the struct is laid out? Of course, my apologies. I was clearly overly terse. I declare the structure packed as follows: typedef struct { uint16_t a; uint32_t b; } __attribute__((packed)) st; void foo(st *s, int n) { memcpy(&s->b, &n, sizeof n); } This code generates the unaligend store: $ arm-elf-objdump -d packed.o ... 0: e24dd004 sub sp, sp, #4 ; 0x4 4: e5801002 str r1, [r0, #2] 8: e28dd004 add sp, sp, #4 ; 0x4 c: e12fff1e bx lr $ arm-elf-gcc --version | head -1 arm-elf-gcc (GCC) 4.0.1 Cheers, Shaun