"Fossies" - the Fresh Open Source Software Archive

Member "FreeBASIC-1.07.1-source/tests/cpp/fbcall-cpp.cpp" (27 Sep 2019, 4733 Bytes) of package /linux/privat/FreeBASIC-1.07.1-source.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 // implementation for fbcall-fbc.bas
    2 
    3 // each operation records call information
    4 // in static variables, and we use getters
    5 // to retrieve it back to fbc side
    6 
    7 #define NULL 0
    8 static const void * ptr1 = NULL;
    9 static const void * ptr2 = NULL;
   10 static const void * ptr3 = NULL;
   11 static char msg1[100];  // check message
   12 
   13 void setMsg( const char* msg ) {
   14     char *s = msg1;
   15     while( *msg )
   16         *s++ = *msg++;
   17     *s = *msg;
   18 }
   19 
   20 void resetChecks() {
   21     ptr1 = NULL;
   22     ptr2 = NULL;
   23     ptr3 = NULL;
   24     setMsg( "" );
   25 }
   26 
   27 const void* getPtr1() { 
   28     return ptr1;
   29 }
   30 
   31 const void* getPtr2() { 
   32     return ptr2;
   33 }
   34 
   35 const void* getPtr3() { 
   36     return ptr3;
   37 }
   38 
   39 char* getMsg1() {
   40     return msg1;
   41 }
   42 
   43 class UDT
   44 {
   45     public:
   46         int value;
   47 };
   48 
   49 /*
   50 Default calling convention for rtlib is either
   51 cdecl or stdcall depending on target platform
   52 Assuming a gcc compiler, stdcall should be
   53 default for windows 32 bit.  For windows 64 bit
   54 it doesn't matter.
   55 */
   56 
   57 #if defined( __CYGWIN__ ) || defined( _WIN32 )
   58     #define FBCALL __attribute__((stdcall))
   59 #else
   60     #define FBCALL __attribute__((cdecl))
   61 #endif
   62 
   63 extern "C" {
   64 void sub1_rtlib_default( UDT const& a ) FBCALL;
   65 void sub1_rtlib_cdecl( UDT const& a  ) __attribute__((cdecl));
   66 void sub1_rtlib_stdcall( UDT const& a ) __attribute__((stdcall));
   67 UDT func1_rtlib_default( UDT const& a ) FBCALL;
   68 UDT func1_rtlib_cdecl( UDT const& a ) __attribute__((cdecl));
   69 UDT func1_rtlib_stdcall( UDT const& a ) __attribute__((stdcall));
   70 
   71 void sub2_rtlib_default( UDT const& a, UDT const& b ) FBCALL;
   72 void sub2_rtlib_cdecl( UDT const& a, UDT const& b ) __attribute__((cdecl));
   73 void sub2_rtlib_stdcall( UDT const& a, UDT const& b ) __attribute__((stdcall));
   74 UDT func2_rtlib_default( UDT const& a, UDT const& b ) FBCALL;
   75 UDT func2_rtlib_cdecl( UDT const& a, UDT const& b ) __attribute__((cdecl));
   76 UDT func2_rtlib_stdcall( UDT const& a, UDT const& b ) __attribute__((stdcall));
   77 
   78 void sub3_rtlib_default( UDT const& a, UDT const& b, UDT const& c ) FBCALL;
   79 void sub3_rtlib_cdecl( UDT const& a, UDT const& b, UDT const& c ) __attribute__((cdecl));
   80 void sub3_rtlib_stdcall( UDT const& a, UDT const& b, UDT const& c ) __attribute__((stdcall));
   81 UDT func3_rtlib_default( UDT const& a, UDT const& b, UDT const& c ) FBCALL;
   82 UDT func3_rtlib_cdecl( UDT const& a, UDT const& b, UDT const& c ) __attribute__((cdecl));
   83 UDT func3_rtlib_stdcall( UDT const& a, UDT const& b, UDT const& c ) __attribute__((stdcall));
   84 }
   85 
   86 extern "C" {
   87 void sub1_rtlib_default( UDT const& a ) {
   88     ptr1 = &a;
   89     setMsg( "sub1_rtlib_default" );
   90 }
   91 
   92 void sub1_rtlib_cdecl( UDT const& a ) {
   93     ptr1 = &a;
   94     setMsg( "sub1_rtlib_cdecl" );
   95 }
   96 
   97 void sub1_rtlib_stdcall( UDT const& a ) {
   98     ptr1 = &a;
   99     setMsg( "sub1_rtlib_stdcall" );
  100 }
  101 
  102 UDT func1_rtlib_default( UDT const& a ) {
  103     UDT ret = {0};
  104     ptr1 = &a;
  105     setMsg( "func1_rtlib_default" );
  106     return ret;
  107 }
  108 
  109 UDT func1_rtlib_cdecl( UDT const& a ) {
  110     UDT ret = {0};
  111     ptr1 = &a;
  112     setMsg( "func1_rtlib_cdecl" );
  113     return ret;
  114 }
  115 
  116 UDT func1_rtlib_stdcall( UDT const& a ) {
  117     UDT ret = {0};
  118     ptr1 = &a;
  119     setMsg( "func1_rtlib_stdcall" );
  120     return ret;
  121 }
  122 
  123 void sub2_rtlib_default( UDT const& a, UDT const& b ) {
  124     ptr1 = &a;
  125     ptr2 = &b;
  126     setMsg( "sub2_rtlib_default" );
  127 }
  128 
  129 void sub2_rtlib_cdecl( UDT const& a, UDT const& b ) {
  130     ptr1 = &a;
  131     ptr2 = &b;
  132     setMsg( "sub2_rtlib_cdecl" );
  133 }
  134 
  135 void sub2_rtlib_stdcall( UDT const& a, UDT const& b ) {
  136     ptr1 = &a;
  137     ptr2 = &b;
  138     setMsg( "sub2_rtlib_stdcall" );
  139 }
  140 
  141 UDT func2_rtlib_default( UDT const& a, UDT const& b ) {
  142     UDT ret = {0};
  143     ptr1 = &a;
  144     ptr2 = &b;
  145     setMsg( "func2_rtlib_default" );
  146     return ret;
  147 }
  148 
  149 UDT func2_rtlib_cdecl( UDT const& a, UDT const& b ) {
  150     UDT ret = {0};
  151     ptr1 = &a;
  152     ptr2 = &b;
  153     setMsg( "func2_rtlib_cdecl" );
  154     return ret;
  155 }
  156 
  157 UDT func2_rtlib_stdcall( UDT const& a, UDT const& b ) {
  158     UDT ret = {0};
  159     ptr1 = &a;
  160     ptr2 = &b;
  161     setMsg( "func2_rtlib_stdcall" );
  162     return ret;
  163 }
  164 
  165 void sub3_rtlib_default( UDT const& a, UDT const& b, UDT const& c ) {
  166     ptr1 = &a;
  167     ptr2 = &b;
  168     ptr3 = &c;
  169     setMsg( "sub3_rtlib_default" );
  170 }
  171 
  172 void sub3_rtlib_cdecl( UDT const& a, UDT const& b, UDT const& c ) {
  173     ptr1 = &a;
  174     ptr2 = &b;
  175     ptr3 = &c;
  176     setMsg( "sub3_rtlib_cdecl" );
  177 }
  178 
  179 void sub3_rtlib_stdcall( UDT const& a, UDT const& b, UDT const& c ) {
  180     ptr1 = &a;
  181     ptr2 = &b;
  182     ptr3 = &c;
  183     setMsg( "sub3_rtlib_stdcall" );
  184 }
  185 
  186 UDT func3_rtlib_default( UDT const& a, UDT const& b, UDT const& c ) {
  187     UDT ret = {0};
  188     ptr1 = &a;
  189     ptr2 = &b;
  190     ptr3 = &c;
  191     setMsg( "func3_rtlib_default" );
  192     return ret;
  193 }
  194 
  195 UDT func3_rtlib_cdecl( UDT const& a, UDT const& b, UDT const& c ) {
  196     UDT ret = {0};
  197     ptr1 = &a;
  198     ptr2 = &b;
  199     ptr3 = &c;
  200     setMsg( "func3_rtlib_cdecl" );
  201     return ret;
  202 }
  203 
  204 UDT func3_rtlib_stdcall( UDT const& a, UDT const& b, UDT const& c ) {
  205     UDT ret = {0};
  206     ptr1 = &a;
  207     ptr2 = &b;
  208     ptr3 = &c;
  209     setMsg( "func3_rtlib_stdcall" );
  210     return ret;
  211 }
  212 } // extern "C"