conversions betwwen function pointers and their calls
Dima Sorkin
dima.sorkin@gmail.com
Sun Sep 28 21:07:00 GMT 2014
Hi,
1. I have read that the C99 standard allows conversions between
function pointer types (6.3.2.3 paragraph 8). But if I don't want
such conversions to appear mistakingly in program - is there any
command line option to issue a warning?
2. Consider the example below, it was compiled by
GCC 4.9.1 20140903 (prerelease) with
'gcc -std=c99 -pedantic -Wall -Wextra'. I don't understand
why the compiler allows calling of function pointer 'g' of
type 'void (*)()' with arguments...
Thanks, regards,
Dima.
----- EXAMPLE: -----
#include<stdio.h>
void f(double x) { printf("x=%f\n",x); }
typedef void (*f_with_no_args_type)();
typedef void (*f_type)(double);
int main() {
// standart allows it (why not still warn?)
f_with_no_args_type g = f;
g(3.14); // <- BUT WHY COMPILER IS SILENT HERE?
g(1.0,2.0,3); // <- AND HERE
g();
f_type h = f;
h(3.14);
// h(1.0,2.0,3); // compilation error -- ok
// h(); // compilation error -- ok
return 0;
}
More information about the Gcc-help
mailing list