This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: -Wcast-align and performance
- From: Ian Lance Taylor <iant at google dot com>
- To: John Boncek <jboncek at Hunter dot COM>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Fri, 13 Mar 2009 17:55:15 -0700
- Subject: Re: -Wcast-align and performance
- References: <22501453.post@talk.nabble.com>
John Boncek <jboncek@Hunter.COM> writes:
> I have turned on -Wcast-align in a big C++ project for ARM PXA270
> architecture and am receiving many warnings of the form:
>
> warning: cast from `BYTE*' to `short int*' increases required alignment of
> target type
>
> This sounds like there will be a performance penalty to generate the correct
> alignment for this. Is that correct?
It depends on the actual value of the pointer. If you take the address
of a short, cast it to char*, and then cast back to short*, you will get
the warning, but there won't be any performance penalty. In other
words, you will get that warning if you use char* like void*.
If you are taking the address of a char array and then casting that to
short*, then you may indeed have a performance penalty. And on some
platforms your program won't work at all.
Ian