pointers to void () vs. ptr to int () with conditional ops

Ihor Kinal ijk at mtung.UUCP
Tue Jul 22 04:17:26 AEST 1986


The following code  does not compile with line 21, yet the equivalent
code using if-else is OK, and the conditional works with int
functions.  Is my lint and compiler broken, or am I overlooking something?

Thanks,
Ihor Kinal
ihnp4!mtung!ijk



/* sample program using conditionals and pointers to functions */
extern	int func_i();
extern	int func_J();
extern	void func_v();
extern	void func_W();

main()
{
	int (*iptr_to_func) ();
	void (*vptr_to_func) ();

	int index = 3;

	iptr_to_func = (index == 0) ? func_i : func_J;

	if (index == 1)
		vptr_to_func = func_v;
	else
		vptr_to_func = func_W;

	vptr_to_func = (index == 1) ? func_v : func_W;

}

/*	following output from lint:


tst.c
==============
(21)  operands of : have incompatible types
(14)  warning: iptr_to_ set but not used in function main
(21)  warning: vptr_to_ set but not used in function main
warning: illegal combination of pointer and integer:
    (21)  operator =


==============
name used but not defined
    func_J   	tst.c(14)
    func_W   	tst.c(21)
    func_i   	tst.c(14)
    func_v   	tst.c(21)

-------	END of lint output ---------------

******* following output from cc:

"tst.c", line 21: operands of : have incompatible types
"tst.c", line 21: warning: illegal combination of pointer and
integer, op =

*/



More information about the Comp.lang.c mailing list