Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: memcpy vs. gcc strict aliasing



On Wed, Dec 03, 2008 at 09:52:51PM +0000, David Laight wrote:
> I just remember problems with sparc and the compiler assuming the
> alignment constraints of the implied type when inlining memcpy().
> Perhaps using the 'as if' rule to avoid doing the copy itself!

All problems I have seen in this area where (at least) "dubious" casts of
the source pointer and always very simple to fix. AFAIR this behaviour
(treating builtin memcpy just as a structure assignment) is backed by
the standard. Don't use a "struct foo" pointer when the thing it points
to is not a struct foo (but only it's bytewise copy in an input stream).
Just memcpy with the char pointer as source and a real struct foo as the
target, and everything is fine.

Martin


Home | Main Index | Thread Index | Old Index