I have the following program:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int my_init(size_t n);
int
my_init(size_t n) { return (int) n; }
int
main(void)
{
int (*init)(size_t n);
init = &my_init;
return 0;
}
and my question is how to correctly assign the function pointer init
. Is it correct to say:
init = &my_init;
or
init = my_init;
Both seem to pass gcc with strict warnings:
gcc -ansi -pedantic -Werror -W -Wall -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Wstrict-prototypes -fshort-enums -fno-common -Wmissing-prototypes -Wnested-externs -Dinline= -g
So which is correct? I even used the lint checker splint
on both versions, and got no warnings in either case.