Article View: gnu.gcc.bug
Article #6398Re: gcc-2.7.1: memcpy() problems persists
From: Paul Eggert
Date: Fri, 24 Nov 1995 00:00
Date: Fri, 24 Nov 1995 00:00
22 lines
1424 bytes
1424 bytes
From: eru@tnso04.tele.nokia.fi (Erkki Ruohtula)
Date: 24 Nov 1995 06:12:02 -0500
even in cases where
*a = *b;
fails because of misaligment, doing the copying using memcpy as in
memcpy(a, b, sizeof(*a));
must not fail.
No, because once the program has generated an invalid pointer, the
resulting behavior is undefined. See ANSI C section 3.3.4 page 46
lines 36-37. For example, on some word-oriented implementations,
sizeof(int*) < sizeof(char*), and attempting to create an unaligned
int* pointer will generate garbage. Any C program that relies on
unaligned pointers has undefined behavior.
If you want an unaligned data pointer, use char* or void*; if you use
a more restrictive type like int*, the standard says that GCC is
entitled to assume that the pointer is properly aligned.
For more on this subject please see Joe Buck's article
<news:410n4j$jqv@hermes.synopsys.com> (1995-08-18).
Technical Details
Message-ID:
<199511241432.GAA15528@tattoo.twinsun.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<199511241109.NAA04283@tnso04.tele.nokia.fi>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 113d02,ffb1e88010d14e37 X-Google-Attributes: gid113d02,public From: eggert@twinsun.COM (Paul Eggert) Subject: Re: gcc-2.7.1: memcpy() problems persists Date: 1995/11/24 Message-ID: <199511241432.GAA15528@tattoo.twinsun.com> X-Deja-AN: 120031660 distribution: gnu sender: daemon@cis.ohio-state.edu references: <199511241109.NAA04283@tnso04.tele.nokia.fi> organization: GNUs Not Usenet newsgroups: gnu.gcc.bug