Topic: Function pointer linkage


Author: jfc@mit.edu (John Carr)
Date: 1995/06/26
Raw View
The ARM distinguished between pointers to C functions and pointers to C++
functions.  The draft standard explicitly drops such a distinction; all
function pointers are alike.

Why was this change made?

It seems to make it impossible to safely mix C and C++ function pointers
except in the special case where the compiler chooses to use the same
calling convention for both languages.

--
    John Carr (jfc@mit.edu)





Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1995/06/26
Raw View
In article 1r6@senator-bedfellow.MIT.EDU, jfc@mit.edu (John Carr) writes:
>The ARM distinguished between pointers to C functions and pointers to C++
>functions.  The draft standard explicitly drops such a distinction; all
>function pointers are alike.

The ARM has commentary which says that you can differentiate a pointer
to a C function from a pointer to a C++ function. It is not at all
clear that the specification part of the ARM makes this in fact
possible. That is, the specification part of the ARM seems to say that
 extern "C" int (*fp)(int);
declares that the pointer fp itself has C linkage (whatever that
means), and says nothing about the function it points to -- the
commentary notwithstanding. But as I said, this isn't completely clear.

>It seems to make it impossible to safely mix C and C++ function pointers
>except in the special case where the compiler chooses to use the same
>calling convention for both languages.

True. In fact, the current wording of the draft could be taken as a constraint
on implementations: C and C++ functions (except non-static member functions)
must use the same calling conventions. (Wait, don't scream yet.)

Whether the linkage (C or C++ or whatever) is, can be, or should be part
of the type of a function -- and thus of a function pointer -- has been the
subject of considerable discussion within the C++ committee. The current
resolution is that it is not part of the type. I believe that decision
will be reviewed and possibly changed.

---
Steve Clamage, stephen.clamage@eng.sun.com