This is the mail archive of the gcc-bugs@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]

Re: memcpy() inlining and alignment


Jason Thorpe <thorpej@netbsd.org> said:
> On Sat, 4 Mar 2000 02:41:05 +0100 
>  "Martin v. Loewis" <martin@loewis.home.cs.tu-berlin.de> wrote:
>  > Since cp+1 is not correctly aligned 'struct s*', assigning it to src
>  > results in undefined behaviour. That, of course, does include the
>  > option of a later memcpy call crashing.

> Okay, so what you're saying is that code that currently says this:
> 
> 	memcpy(&dst.i, &src->i, sizeof(dst.i));
> 
> should read:
> 
> 	memcpy(&dst.i, char_ptr_to_src + offsetof(struct s, i), sizeof(dst.i));
> 
> Ok, thanks for the dicussion, folks...

If *src is aligned correctly, so is src->i. Repeat with src --> dst. If
not, you'll have to go through contortions anyway.
-- 
Horst von Brand                             vonbrand@sleipnir.valparaiso.cl
Casilla 9G, Viņa del Mar, Chile                               +56 32 672616


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