-Wcast-align and performance
Ian Lance Taylor
iant@google.com
Sat Mar 14 00:55:00 GMT 2009
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
More information about the Gcc-help
mailing list