tech-userlevel archive

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

Re: why cast to char* through void*



On Wed, Jul 01, 2009 at 10:16:05PM -0400, Thor Lancelot Simon wrote:
> On Wed, Jul 01, 2009 at 11:31:53PM +0000, David Holland wrote:
> > 
> > The compiler is allowed to assume that two pointers of different types
> > point to things that don't overlap.
> 
> But there's an exception for pointers of type char *, isn't there?  At
> least, I thought I remembered it was char *, but now I suspect it's
> void *.

There is an exception for 'char *'.

But gcc will track the original pointer type through casts (probably
especially to 'void *'!) which it uses to remember the alignment
constraint of the pointer - which is fubar when you are trying to
use memcpy() to copy from a misaligned pointer.
Technically you can't have a misaligned pointer ...

        David

-- 
David Laight: david%l8s.co.uk@localhost


Home | Main Index | Thread Index | Old Index