News:

This week IPhone 15 Pro winner is karn
You can be too a winner! Become the top poster of the week and win valuable prizes.  More details are You are not allowed to view links. Register or Login 

Main Menu

Cannot portably call a static member function from C

Started by ben2ong2, October 06, 2006, 10:58:53 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ben2ong2

[ Example adapted from "C++ Gotchas", tutorial notes by
  Tom Cargill, p. 55 ]

/* ........................................................... */
/* callback.c                                                  */

typedef void (*fptr) (int, int)

void callback (fptr fp)
{
   (*fp) (111, 222);
}

// ...........................................................
// You are not allowed to view links. Register or Login

#include <iostream.h>


typedef void (*fptr) (int, int)

extern "C" void callback (fptr);


class C {
  public:
    static void f (int, int);
};

void C :: f (int a, int b)
{
    cout << "a=" << a << "b=" << b << endl;
}


int main ()
{
   callback ((fptr) &C::f);
   return 0;
}

// ...........................................................

The output from one system might be

a=111 b=222

The output from another system might be

a=222 b=111


ARM 7.4

   Since functions with different linkage may have different
   calling conventions, a linkage specification may have a major
   effect on pointers to functions.  In particular, C++ functions
   that do not have the ellipsis in their argument type may use a
   more efficient calling sequence than has traditionally been used
   for C functions.
You are not allowed to view links. Register or Login
You are not allowed to view links. Register or Login