This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: memcpy() inlining and alignment
- To: Jason Thorpe <thorpej at netbsd dot org>
- Subject: Re: memcpy() inlining and alignment
- From: Horst von Brand <vonbrand at sleipnir dot valparaiso dot cl>
- Date: Sat, 04 Mar 2000 12:35:20 -0300
- cc: gcc-bugs at gcc dot gnu dot org, davem at redhat dot com, sommerfeld at netbsd dot org
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