[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <46f6a94a518e468c82f19c5250878529@AcuMS.aculab.com>
Date: Fri, 2 Oct 2020 13:26:35 +0000
From: David Laight <David.Laight@...LAB.COM>
To: 'Jonathan Wakely' <jwakely.gcc@...il.com>,
Alejandro Colomar <colomar.6.4.3@...il.com>
CC: "Michael Kerrisk (man-pages)" <mtk.manpages@...il.com>,
linux-man <linux-man@...r.kernel.org>,
gcc-patches <gcc-patches@....gnu.org>,
"GNU C Library" <libc-alpha@...rceware.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"eggert@...ucla.edu" <eggert@...ucla.edu>
Subject: RE: [PATCH 1/2] system_data_types.7: Add 'void *'
> > +.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)
Powered by blists - more mailing lists