------- Additional Comments From joseph at codesourcery dot com 2004-11-09
23:47 -------
Subject: Re: Warning not legitimate
On Tue, 9 Nov 2004, manus at eiffel dot com wrote:
> extern void f();
>
> void g(int a) {
> void * fnptr = f;
>
> ((void (*) (int)) fnptr) (a); /* Ok. */
If you want diagnostics for conversions between object and function
pointers, use -pedantic.
> ((void (*) (int)) f)(a); /* Not Ok. */
> }
>
> Why `char' does trigger the warning and not `int'? This looks like a bug to
> me.
The function type compatibility rules are defined in C99 6.7.5.3#15. In
particular:
If one type has a parameter type list and the other
type is specified by a function declarator that is not part
of a function definition and that contains an empty
identifier list, the parameter list shall not have an
ellipsis terminator and the type of each parameter shall be
compatible with the type that results from the application
of the default argument promotions.
char promotes to int under the default argument promotions, and char and
int are not compatible, whereas int promotes to itself.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18411