Borland style __closure in gcc

I am new to programming with gnu C ++. I have an application that I decided to convert to a cross platform, and I started using C :: B about two months ago. I had a lot of problems, but I decided that they save the source code in #ifdef BCB ... #else ... #endif blocks for object classes or structures. I can not solve the following problem because it is very difficult. Function declarations have been operating since 1997/1998, and each point of the application (s) has been developed with these definitions and implementations in mind. They are used for inter-object, interprocess and network communication and the entire interactive event system. Any function anywhere can be called with any number (up to 50) of parameters directly or via streaming connections, while our JetRtl.dll is ready for service, and the caller knows the number of parameters. I have been explaining for so long because, as far as I see, many simply ask “Why ...” or allow the child’s solution to work only in “Hello World” applications.

Here is the header file. The #else .... #endif section has recently been 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 do GCC (MinGW 4.71, I also have 4.92) to understand the expression typedef void __cdecl (__closure *JFXC)(); ;?"

Expressions without __closure compile and work as expected.

+6
source share
2 answers

Replacement for __closure

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

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

... can be replaced with these C ++ 11 bits

 struct S { void f(){} }; S s; typedef std::function<void()> JFXC; JFXC jfxc (std::bind (&S::f, &s)); jfxc(); 
+5
source

I solved my part of the problem. The JFXC function type is used to control object methods as pointers (and not for calling methods), and the rest is used as library (assembler) functions. With gcc, I could not assign or attribute any member functions to the generic object :: method type. The following definitions allow this, but it still has problems trying to call, but on my side, since the FNXC types are handled using manually developed / modified assemmbly modules, there is no compilation problem. The only problem for me was that I was hoping that gcc would create ready-made code for target platforms and architectures. The following changes made to the code above are compiled anyway. You can uncomment the #ifndef __closure section.

 typedef void __cdecl (*JF_C)(); #ifdef BCB typedef void __cdecl (__closure *JFXC)(); #else class ANY; /*#ifndef __closure # define __closure ANY:: #endif*/ #ifdef __closure typedef void __cdecl (__closure *JFXC)(); #else typedef void __cdecl (*JFXC)(ANY&, void (ANY::*)()); #endif #endif // BCB 

Thanks to everyone who replied to the message.

0
source

Source: https://habr.com/ru/post/980501/


All Articles