linux-man.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: 'Jonathan Wakely' <jwakely.gcc@gmail.com>,
	Alejandro Colomar <colomar.6.4.3@gmail.com>
Cc: "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com>,
	linux-man <linux-man@vger.kernel.org>,
	gcc-patches <gcc-patches@gcc.gnu.org>,
	"GNU C Library" <libc-alpha@sourceware.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"eggert@cs.ucla.edu" <eggert@cs.ucla.edu>
Subject: RE: [PATCH 1/2] system_data_types.7: Add 'void *'
Date: Fri, 2 Oct 2020 13:26:35 +0000	[thread overview]
Message-ID: <46f6a94a518e468c82f19c5250878529@AcuMS.aculab.com> (raw)
In-Reply-To: <CAH6eHdQD+4g4ne9akZ5TDbhfq9TR0JSSBQ5H+W+Fab=5dy7O+g@mail.gmail.com>

> > +.I void *
> > +.RS
> > +According to the C language standard,
> > +a pointer to any object type may be converted to a pointer to
> > +.I void
> > +and back.
> > +POSIX further requires that any pointer,
> > +including pointers to functions,
> > +may be converted to a pointer to
> > +.I void
> > +and back.
> > +.PP
> > +Conversions from and to any other pointer type are done implicitly,
> > +not requiring casts at all.
> > +Note that this feature prevents any kind of type checking:
> > +the programmer should be careful not to cast a
> > +.I void *
> > +value to a type incompatible to that of the underlying data,
> > +because that would result in undefined behavior.
> > +.PP
> > +This type is useful in function parameters and return value
> > +to allow passing values of any type.
> > +The function will usually use some mechanism to know
> > +of which type the underlying data passed to the function really is.
> 
> This sentence seems clunky.
> 
> How about "The function will typically use some mechanism to know the
> real type of the data being passed via a pointer to void."
> 
> An example of "some mechanism" might be useful, though I don't have
> one to offer.

It's also bollocks.

There are two main places 'void *' is used:
1) buffers (eg functions like read() and write()) when the
   associated byte length is also passed.
   This (sort of) includes memory allocation functions.
2) Passing a parameter for a callback function.
   In this case the pointer is always cast back to
   the original type before being used.
   
What it shouldn't be used for is structures you don't
want other code to look inside - use incomplete structs.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

  reply	other threads:[~2020-10-02 13:26 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-02 12:16 [PATCH 0/2] Document 'void *' Alejandro Colomar
2020-10-02 12:16 ` [PATCH 1/2] system_data_types.7: Add " Alejandro Colomar
2020-10-02 13:15   ` Jonathan Wakely
2020-10-02 13:26     ` David Laight [this message]
2020-10-02 12:16 ` [PATCH 2/2] void.3: New link to system_data_types(7) Alejandro Colomar
2020-10-02 15:14 ` [PATCH v4 0/2] Document 'void *' Alejandro Colomar
2020-10-02 19:28   ` [PATCH v5 " Alejandro Colomar
2020-10-02 19:28   ` [PATCH v5 1/2] system_data_types.7: Add " Alejandro Colomar
2020-10-03  8:01     ` Michael Kerrisk (man-pages)
2020-10-02 19:28   ` [PATCH v5 2/2] void.3: New link to system_data_types(7) Alejandro Colomar
2020-10-03  8:01     ` Michael Kerrisk (man-pages)
2020-10-02 15:14 ` [PATCH v4 1/2] system_data_types.7: Add 'void *' Alejandro Colomar
2020-10-02 16:53   ` Paul Eggert
2020-10-02 18:38     ` Alejandro Colomar
2020-10-02 20:14       ` Paul Eggert
2020-10-02 20:27         ` Alejandro Colomar
2020-10-03  7:10           ` Michael Kerrisk (man-pages)
2020-10-03  7:48             ` G. Branden Robinson
2020-10-03  8:55               ` Alejandro Colomar
2020-10-03 11:47                 ` Alejandro Colomar
2020-10-03 11:52               ` Michael Kerrisk (man-pages)
2020-10-02 15:14 ` [PATCH v4 2/2] void.3: New link to system_data_types(7) Alejandro Colomar
  -- strict thread matches above, loose matches on Subject: below --
2020-10-01 15:06 [PATCH 0/2] Document void * Alejandro Colomar
2020-10-01 15:06 ` [PATCH 1/2] system_data_types.7: Add 'void *' Alejandro Colomar

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=46f6a94a518e468c82f19c5250878529@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=colomar.6.4.3@gmail.com \
    --cc=eggert@cs.ucla.edu \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jwakely.gcc@gmail.com \
    --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).