[comp.lang.c] Nested function prototypes: bug in VAX C v2.3

S170MIKO%HTIKUB5.BITNET@wiscvm.wisc.EDU (08/13/87)

Greetings all.

After installing VAX C v2.3 I added prototypes and recompiled all my
C-modules, and hit a clear bug with nested prototypes (really pointers
to functions with prototypes).

The following piece of code:
     void f1(void (*p1) (void));
     typedef void (*func_t) (int);
     void f2(func_t p2)
     { (*p2)(5); }
makes the compiler complain:
          { (*p2)(5); }
     INVCONVERT, The source or target of a conversion is noncomputational.
                At line number 4 in USER01:[S170.C]BUG.C;1.
     MISARGNUMBER, The number of arguments passed to the function does not
                match the number declared in a previous function prototype.
                At line number 4 in USER01:[S170.C]BUG.C;1.

It compiles ok if
  a. lines 1 and 2 are reversed, or
  b. p1 and p2 differ in result-type, or
  c. the "5" in line 4 is left out, or
  d. the third "void" in line 1 is left out, or
  e. all three "*"s are left out (but then you can't call f2!);
but leaving out "int" in line 2 of changing it to something else makes no
difference.

After some more trying it is clear that the compiler notices only the
first prototype it sees for any type pointer_to_function_returning_foo
and ignores all others.

I hit this bug when compiling a module that contains a function like f2
above, and also #includes stdlib.h which contains the line
    int atexit(void (*func) (void));
                             ^^^^

I will of course SPR this problem, but I thought I'd let you all know
first and invite comments/flames.
My advice is not to use function prototypes with pointer_to_function
yet (and hence no nested prototypes), and to change stdlib.h (remember:
even if you don't use prototypes, you're still in trouble if you use
pointer_to_function_returning_void).

I'm posting this message to INFO-VAX and INFO-C: sorry if you see it
twice.

                                     Michiel

----------------------------------------------------------------------
Michiel Koren            EARN/Bitnet:  s170miko@htikub5
Tilburg University       SURFnet:      kubvx1::s170miko
Netherlands              PSI-mail:     PSI%+204 1420061 0610::s170miko
                         Phone:        +31 13 662559
                         Papernet:     P.O.Box 90153
                                       5000 LE TILBURG
----------------------------------------------------------------------