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: Alignment - Structures and Other Things


On Wed, Apr 13, 2011 at 9:56 PM, kevin diggs <diggskevin38@gmail.com> wrote:
> Even if it doesn't break it will likely incur a performance penalty
> from unaligned accesses, right?

Yes, in best case it will only be slow.
(however, you may have a 8 bit CPU or so, needing byte-boundary
alignment only :)).

I had some ARM boards where things like
  ((struct foo*)(&recv_buf[123]))->mess.cmd
do crash (but code was not generated with gcc), as far as I know
it is possible that compilers generate code to access using
multiple aligned access instructions, but I guess some CPUs do
this internally automatically (because the same binary code did
not crash on different [older/smaller/slower] ARM CPUs).

So I think the code example with (struct f*)(malloc(s)+1) may run
(slowly) in exceptional/lucky cases, but is not correct and
should be fixed, if possible.

oki,

Steffen


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