Another C bug?

Steve langer langer at rainbow.uchicago.edu
Fri Jul 27 06:01:43 AEST 1990


 I've been having trouble with the MIPS C compiler on a
Silicon Graphics 4D/220 (3.2). I think this is slightly different
than the (void *) bug that was discussed here recently. The
problem is that pointers to functions returning void aren't
treated properly.

The following program doesn't compile if TYPE is defined to be
"void". It works if TYPE is defined to be "int". It compiles
(and works!) in both cases on a Sun.

#include <stdio.h>

#define TYPE void

TYPE func() {             /* A function */
   printf("funk!\n");
}

main() {
   TYPE (*function)();     /* A Pointer to a function */
   int test = 1;
   function = func;
   if(func == function) (*function)();  /* This line doesn't compile! */
}

Here's what the compiler says:
rainbow74 >> cc junk.c
ccom: Error: junk.c, line 13: operands of == have incompatible types
         if(func == function) (*function)();
      ----------------------^

I get the same thing if I try to use something like
   void (*f)(), (*g)();
   int flag;
   anotherfunction(flag ? f : g);   /* incompatible types for ":" ???? */


Thanks for any advice.

             Steve  (langer at control.uchicago.edu)



More information about the Comp.sys.sgi mailing list