This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: -Wcast-align and performance


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]