function pointer help needed
Ron Natalie <ron>
ron at brl-sem.ARPA
Thu Jan 15 08:57:36 AEST 1987
In article <592 at elrond.UUCP>, amamaral at elrond.UUCP (Alan Amaral) writes:
> In article <1327 at loral.UUCP>, jlh at loral.UUCP (Jim Vaxkiller) writes:
> Here is one way:
>
> void /* 2 do nothing routines returning */
> err0() /* different data types */
> {printf("testing 123\n");}
>
> int
> err1()
> {}
>
> void (*ptr_tbl[2])(); /* table of 2 function pointers */
>
> void init()
> {
> ptr_tbl[0] = err0;
> }
WARNING WARNING...DANGER DANGER...RUN, WILL ROBINSON, RUN!
Gak...don't do this. While most compilers will treat this OK since the
place where an "int" is returned is generally considered scratch before
a funcion is called, this is NOT PORTABLE, and will break most compilers
if err0 returned something large like a structure.
The linkage of a subroutine is dependant on the value it returns. Casting
it into a pointer to a function returning a different type is asking for
trouble.
-Ron
More information about the Comp.lang.c
mailing list