From: David Laight <David.Laight@ACULAB.COM>
To: 'Alejandro Colomar' <colomar.6.4.3@gmail.com>,
Paul Eggert <eggert@cs.ucla.edu>
Cc: "mtk.manpages@gmail.com" <mtk.manpages@gmail.com>,
"linux-man@vger.kernel.org" <linux-man@vger.kernel.org>,
"libc-alpha@sourceware.org" <libc-alpha@sourceware.org>,
"gcc@gcc.gnu.org" <gcc@gcc.gnu.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH v2 1/2] system_data_types.7: Add 'void *'
Date: Fri, 2 Oct 2020 09:10:28 +0000 [thread overview]
Message-ID: <a2c3ceecca7648b3bb33f1c8bf8e7893@AcuMS.aculab.com> (raw)
In-Reply-To: <4b86f6e9-0d8a-f14a-73ce-ebbdc9d9edba@gmail.com>
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)
next prev parent reply other threads:[~2020-10-02 9:10 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <41affebd-3354-9420-0048-bffd14535e95@gmail.com>
[not found] ` <20201001154946.104626-2-colomar.6.4.3@gmail.com>
[not found] ` <538b683f-01d2-6148-4f1d-1b293eb5cd6b@cs.ucla.edu>
2020-10-02 8:24 ` [PATCH v2 1/2] system_data_types.7: Add 'void *' Alejandro Colomar
2020-10-02 8:48 ` Alejandro Colomar
2020-10-02 11:44 ` Michael Kerrisk (man-pages)
2020-10-02 9:10 ` David Laight [this message]
2020-10-02 17:00 ` Paul Eggert
2020-10-02 10:49 ` Jonathan Wakely
2020-10-02 11:31 ` Michael Kerrisk (man-pages)
2020-10-02 13:06 ` Jonathan Wakely
2020-10-02 13:20 ` Alejandro Colomar
2020-10-02 13:27 ` Jonathan Wakely
2020-10-02 13:51 ` Alejandro Colomar
2020-10-03 8:00 ` Navigational corrections (was: Re: [PATCH v2 1/2] system_data_types.7: Add 'void *') Michael Kerrisk (man-pages)
2020-10-03 9:16 ` Navigational corrections Alejandro Colomar
2020-10-03 11:39 ` Michael Kerrisk (man-pages)
2020-10-05 22:08 ` Alejandro Colomar
2020-10-07 6:53 ` Michael Kerrisk (man-pages)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a2c3ceecca7648b3bb33f1c8bf8e7893@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=colomar.6.4.3@gmail.com \
--cc=eggert@cs.ucla.edu \
--cc=gcc@gcc.gnu.org \
--cc=libc-alpha@sourceware.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-man@vger.kernel.org \
--cc=mtk.manpages@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).