[net.lang.c] Assignment to pointers to functions returning void

joe@teltone.UUCP (Joe) (03/02/84)

This may not be news to you but it was news to me.  The 4.1 BSD C
complier barfs when an attempt is made to assign the address of a
function returning void to a variable declared as a pointer to a
function returning void.  Example code can be found below.  Can
I say that the compilier voids on voids or should I send this line
to net.jokes.  Enjoy. 

Joe Brady  ..!uw-beaver!teltone!joe.
==================================================================
/* Program demonstrates a bug in the VAX 4.1 BSD C compilier.
 * The following error messages is printed:
 * "junk.c", line 17: operands of = have incompatible types
 */
short 	f0();
void 	f1();
int 	f2();

main()
{
    short 	(*pf0)(); 
    void 	(*pf1)();
    int 	(*pf2)();

    pf0 = f0;
    pf1 = f1;			/* This is line 17 */
    pf2 = f2;
}

karn@allegra.UUCP (Phil Karn) (03/03/84)

By wild coincidence, after hundreds of net.lang.c articles with esoteric
and/or uninteresting problems, I see two in a row that I've just
encountered.

I haven't gotten any compiler error messages when assigning the address
of a function which retuns null to a pointer of that type, but lint does
complain bitterly.  Some lints (such as the System V) have this fixed.
I just put up with the noise. If you don't like that, a temporary fix
of the form

#define void int

will quiet things down until you get a fixed lint.

I too was looking for a clean way to declare a pointer to the end of a
structure within a structure, but I think you can get the effect you
want with a little simple pointer arithmetic and casting:

struct foo {
	int retch;
	int bletch;
};

struct foo *foop;
char *charp;

foop = (struct foo *)malloc(100);
charp = (char *)(foop + 1);

--Phil

usenet@abnjh.UUCP (usenet) (03/03/84)

>> /* Program demonstrates a bug in the VAX 4.1 BSD C compilier.
>>  * The following error messages is printed:
>>  * "junk.c", line 17: operands of = have incompatible types
>>  */
>> short 	f0();
>> void 	f1();
>> int 	f2();
>> 
>> main()
>> {
>>     short 	(*pf0)(); 
>>     void 	(*pf1)();
>>     int 	(*pf2)();
>> 
>>     pf0 = f0;
>>     pf1 = f1;			/* This is line 17 */
>>     pf2 = f2;
>> }

When I tried your program on System V on a VAX, I got no diagnostics
of the type mentioned.  Of course, there were some complaints about
undefined symbols when I tried to link the resulting dot-o. :=)
Rick Thomas