This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Alignment Guarantees?
- From: Ian Lance Taylor <iant at google dot com>
- To: noloader at gmail dot com
- Cc: GCC Users List <gcc-help at gcc dot gnu dot org>
- Date: Mon, 05 Mar 2012 12:38:15 -0800
- Subject: Re: Alignment Guarantees?
- Authentication-results: mr.google.com; spf=pass (google.com: domain of iant@google.com designates 10.68.136.231 as permitted sender) smtp.mail=iant@google.com; dkim=pass header.i=iant@google.com
- References: <CAH8yC8nNyVwoWAgKJ1FRYZZe8bKO8Zep1cQt+sZzNz3oVuh5iw@mail.gmail.com>
Jeffrey Walton <noloader@gmail.com> writes:
> Does C/C++ or GCC offer any alignment guarantees? I'm looking at some
> code for ARM that does not look quite right.
>
> void foo(__u8 my_arr[64])
> {
> ...
>
> for(int i = 0; i < 16; i++)
> (__u32*)my_arr[i] = ...
> }
>
> Casting a u8[] to something else has caused a lot of intermittent
> problems on Windows Mobile (ARM) in the past.
To address the code, there is no guarantee that a __u8 is aligned
correctly for a __u32 (assuming those types have their implied meaning).
And note that if __u8 is not "char", "signed char", or "unsigned char",
then this would be an aliasing violation.
Ian