Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!seismo!brl-adm!brl-sem!ron
From: ron@brl-sem.ARPA (Ron Natalie )
Newsgroups: comp.lang.c
Subject: Re: function pointer help needed
Message-ID: <580@brl-sem.ARPA>
Date: Wed, 14-Jan-87 17:57:36 EST
Article-I.D.: brl-sem.580
Posted: Wed Jan 14 17:57:36 1987
Date-Received: Thu, 15-Jan-87 03:09:43 EST
References: <1327@loral.UUCP> <592@elrond.UUCP>
Organization: Electronic Brain Research Lab
Lines: 31
Keywords: (*ptr[i])() = ???

In article <592@elrond.UUCP>, amamaral@elrond.UUCP (Alan Amaral) writes:
 > In article <1327@loral.UUCP>, jlh@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