Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Borland style __closure in gcc

I am new in programming with gnu C++. I have an application which I thought to be converted to cross platform and I began to use C::B about two months ago. I had many problems but I solved them keeping original code in #ifdef BCB ... #else ... #endif blocks for objects classes or structs. I am not able to solve the following problem because it is very complicated. The function declarations have been working since 1997/1998 and every point of the application(s) was developed relying on these definitions and implementations. They are used for inter-object, inter-process, and network communication and all interactive event system. Any function anywhere can be called with any number (up to 50) of parameters directly, or via stream connections as long as our JetRtl.dll is ready to serve and caller knows the number of parameters. I explained so long because as far as I see, many people simply ask "Why ...", or give childish solution to be worked only in "Hello World" apps.

Here is the header file. #else .... #endif section has been recently added.

#ifndef fcalls_h
#define fcalls_h

#include <jettip.h>
#include <stdarg.h>

//  CM_FN_.. calls non member F(...), (ecx & 4) == 0
#define CM_FN_C 0x8FF0 // __cdecl non member F(...)
#define CM_FN_F 0x8FF1 // __fastcall non member F(...)
#define CM_FN_P 0x8FF2 // __pascal non member F(...)
#define CM_FN_S 0x8FF3 // __stdcall non member F(...)

//  CM_FNX.. calls  member X::F(...), (ecx & 4) == 4
#define CM_FNXC 0x8FF4 // __cdecl member X::F(...)
#define CM_FNXF 0x8FF5 // __fastcall member X::F(...)
#define CM_FNXP 0x8FF6 // __pascal member X::F(...)
#define CM_FNXS 0x8FF7 // __stdcall member X::F(...)

#define CM_TERK 0xFFFE // Quits message loop
#define CM_DELW 0x8FFF // destroy link window

typedef void __cdecl    (*JF_C)();
#ifdef BCB
typedef void __cdecl    (__closure *JFXC)();
#else
template<class T> class FXT{};
template<class R> class FXT<R()>{};
template<class R,class A> class FXT<R(A)>{};
template<class R,class A,class B> class FXT<R(A,B)>{};
template<class R,class A,class B,class C> class FXT<R(A,B,C)>{};
template<class R,class A,class B,class C,class D> class FXT<R(A,B,C,D)>{};
template<class R,class A,class B,class C,class D, class E> class FXT<R(A,B,C,D,E)>{};
template<class R,class A,class B,class C,class D, class E,class F> class FXT<R(A,B,C,D,E,F)>{};
template<class R,class A,class B,class C,class D, class E,class F,class G> class    FXT<R(A,B,C,D,E,F,G)>{};

typedef FXT<void __cdecl (void*)> JFXC;
#endif

JF_C __cdecl F_CP(...);
JFXC __cdecl FXCP(...);
JF_C __cdecl _F_CP(int yer, ...);
JFXC __cdecl _FXCP(int yer, ...);

long __fastcall RunFN_C(va_list list, long args);
long __fastcall RunFN_F(va_list list, long args);
long __fastcall RunFN_P(va_list list, long args);
long __fastcall RunFN_S(va_list list, long args);

long __fastcall RunFNXC(va_list list, long args);
long __fastcall RunFNXF(va_list list, long args);
long __fastcall RunFNXP(va_list list, long args);
long __fastcall RunFNXS(va_list list, long args);

// Dispatches the function call into appropirate function; fnx(list, args)
long  __fastcall JetTip DispCall(va_list list, long args, int call);

#endif

The big question is "How can I make GCC (MinGW 4.71, I also have 4.92) to understand the expression typedef void __cdecl (__closure *JFXC)();?"

Expressions without __closure compiles and works as expected.

like image 700
İlhan ÇELİK Avatar asked Jan 04 '15 19:01

İlhan ÇELİK


1 Answers

Replacement for __closure

It seems to me that these bits of Borland C++ ...

struct S { void f(){} };
S s;
typedef void __cdecl (__closure *JFXC)();
JFXC jfxc (&(s.f));
jfxc();

... can be replaced by these bits of C++11

struct S { void f(){} };
S s;
typedef std::function<void()> JFXC;
JFXC jfxc (std::bind (&S::f, &s));
jfxc();
like image 196
wilx Avatar answered Sep 19 '22 18:09

wilx