Casting void - int question

bright at dataio.UUCP bright at dataio.UUCP
Thu Oct 16 02:54:28 AEST 1986


In article <26 at orion.UUCP> heins at orion.UUCP (Michael T. Heins) writes:
>I have a number of existing functions with compatible arguments.  Some
>are declared as void, and others as int.  None of the return values are
>used.  I wish to set up an array of pointers to these functions.
>My problem is that the compiler complains about incompatible types, and
>I can't figure out how to use casts or unions to solve the problem.
>Re-declaring the functions is not an option.  I have exemplified the
>situation below:
>
>int fna() { }
>void fnb() { }
>
>int (*array[32])();
>main() {
>    array[0] = fna;
>    array[1] = fnb; /* This won't work as-is. */
>}
>
>I have tried things like
>	array[1] = (int (*)())fnb;
>but this generates the message "operands of CAST have incompatible types".

int fna() { }
void fnb() { }

int callfnb() { fnb(); }

int (*array[32])();
main() {
    array[0] = fna;
    array[1] = callfnb;
}

Messy, but workable.



More information about the Comp.lang.c mailing list