[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <a2c3ceecca7648b3bb33f1c8bf8e7893@AcuMS.aculab.com>
Date: Fri, 2 Oct 2020 09:10:28 +0000
From: David Laight <David.Laight@...LAB.COM>
To: 'Alejandro Colomar' <colomar.6.4.3@...il.com>,
Paul Eggert <eggert@...ucla.edu>
CC: "mtk.manpages@...il.com" <mtk.manpages@...il.com>,
"linux-man@...r.kernel.org" <linux-man@...r.kernel.org>,
"libc-alpha@...rceware.org" <libc-alpha@...rceware.org>,
"gcc@....gnu.org" <gcc@....gnu.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: RE: [PATCH v2 1/2] system_data_types.7: Add 'void *'
From: Alejandro Colomar
> Sent: 02 October 2020 09:25
> > For 'void *' you should also mention that one cannot use arithmetic on
> > void * pointers, so they're special in that way too.
>
> Good suggestion!
Except that is a gcc extension that is allowed in the kernel.
> > Also, you should
> > warn that because one can convert from any pointer type to void * and
> > then to any other pointer type, it's a deliberate hole in C's
> > type-checking.
>
> Also good. I'll talk about generic function parameters for this.
That isn't what the C standard says at all.
What is says is that you can cast any data pointer to 'void *'
and then cast it back to the same type.
This matters because the compiler will 'remember' structure
alignment through 'void *' casts.
So you can't use memcpy() to copy from a potentially misaligned
(typed) pointer.
'void *' should only be used for structures that are 'a sequence of bytes'.
(eg things that look a bit like read() or write()).
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Powered by blists - more mailing lists