This is the mail archive of the gcc@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: memcpy to an unaligned address


On Tue, Aug 02, 2005 at 04:07:00PM -0600, Shaun Jackman wrote:
> On 8/2/05, Joe Buck <Joe.Buck@synopsys.com> wrote:
> > I suppose we could make & on an unaligned project return a void*.  That
> > isn't really right, but it would at least prevent the cases that we know
> > don't work from compiling.
> 
> That sounds like a dangerous idea only because I'd expect...
> 	int *p = &packed_struct.unaligned_member;
> ... to fail if unaligned_member is not an int, but if the & operator
> returns a void*, it would suddenly become very permissive.

Ah.  I was thinking as a C++ programmer, where void* cannot be assigned to
int* without an explicit cast.  The decision to allow this in C was the
worst mistake the standards committee made.

The problem is that the type returned by malloc is not just any void*,
but a special pointer that is guaranteed to have alignment sufficient
to store any type.  This is very different from the type of the arguments
to memcpy, which is assumed to have no alignment that can be counted on.


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