This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Add a warning for invalid function casts
On Tue, 10 Oct 2017, Martin Sebor wrote:
> > I know of pre-existing code-bases where a type-cast to type:
> > void (*) (void);
> >
> > .. is already used as a generic function pointer: libffi and
> > libgo, I would not want to break these.
>
> Why not fix them instead? They're a part of GCC so it should
> be straightforward. It doesn't seem like a good tradeoff to
Sometimes an interface needs to store an arbitrary function type for which
an ABI-compliant call ends up being constructed at runtime from assembly
language (or from non-C, in general). That's the sort of thing libffi
does - so it inherently needs to be able to take pointers to arbitrary
function types, which thus need to be converted to a generic function
type, and the de facto generic function pointer type in C is void (*)
(void). (C11 6.11.6 says "The use of function declarators with empty
parentheses (not prototype-format parameter type declarators) is an
obsolescent feature.", so void (*) () is best avoided.) Likewise
interfaces such as dlsym (which happens to return void * along with a
special case in POSIX requiring conversions between void * and function
pointers to work, but void (*) (void) is the natural type for such
interfaces to use).
--
Joseph S. Myers
joseph@codesourcery.com