Topic: C vs C++ calling sequence (was cast member funct ptr to pfn?)


Author: jamshid@ses.com (Jamshid Afshar)
Date: Mon, 23 May 1994 05:21:23 GMT
Raw View
Redirected to comp.std.c++.

In article <KANZE.94May9193709@slsvhdt.us-es.sel.de>,
James Kanze <kanze@us-es.sel.de> wrote:
>In article <CpCIEK.2IE@microsoft.com> jimad@microsoft.com (Jim Adcock)
>writes:
|
>|> *Static* member functions can be cast to "C" function type, while allowing
>|> you to keep the function name in the class namespace.
>
>For some implementations, as has been pointed out in another thread.
>In particular, I would expect that good compilers for 80x86 will not
>support this.  (Typically, C functions will require the caller to do
>stack clean-up, whereas C++ functions will have the callee do it.)

I missed that thread, but there is no difference between ANSI C and
C++ in this regard.  It is illegal in ANSI C to call a function with a
different number or type of arguments from the parameters declared in
the function definition.  ANSI C requires that functions taking
variable arguments be prototyped before use using the ellipses
notation.

K&R1 didn't have the ellipses, function prototypes, or
<vararg.h>/<stdarg.h>, but it was hazy about the subject and stressed
that there is no portable way to write a function taking a variable
number of arguments: "printf, the most common C function with a
variable number of arguments, [...] is also non-portable and must be
modified for different environments".

Point being, there's nothing stopping a C compiler vendor from using
more efficient calling sequences or even type-safe linkage except
their users who have a lot of broken code (at least in the eyes of
ANSI C).

Jamshid Afshar
jamshid@ses.com