Hi,

I've just make few tests with OpenWatcom and checked how it generates
startup code for C++ static initialization.
It uses "XI" data segment to store list of pairs:
   { ushort 0x4000, void (*func_ptr)(void) }
So we can reach the same effect using #pragma(s), i.e.:

   void init_func( void )
   {
      [...]
   }


   #define HB_WATCOM_START_SEGMENT     "XI"
   #define HB_WATCOM_STARTUP_ID        0x4000

   #pragma data_seg( HB_WATCOM_START_SEGMENT )
   #pragma off (unreferenced)    /* to disable unused variable warnings */

   static unsigned short _s_init_id_ = HB_WATCOM_STARTUP_ID;
   static void ( * _s_init_func_ ) ( void ) = init_func;

   #pragma on (unreferenced)     /* to enable unused variable warnings */
   #pragma data_seg()

I've checked that it works in WIN32 builds what allows to use OpenWatcom
in C mode to compile Harbour code.
I can add it as separate initialization method but because it uses
#pragma directives and OpenWatcom does not support C99 _Pragma()
then it cannot be done using macros only and it's necessary to add
additional code to each file which needs startup initialization.
But if you look at above code carefully then you will find that it's
in practice the same initialization method as used by MSC so instead
of adding

   #elif defined( HB_WATCOMC_STARTUP )
      [...]

to each file which already has:

   #elif defined( HB_MSC_STARTUP )
      #if defined( HB_OS_WIN_64 )
         #pragma section( HB_MSC_START_SEGMENT, long, read )
      #endif
      #pragma data_seg( HB_MSC_START_SEGMENT )
      static HB_$INITSYM _hb_vm_auto_init_func = init_func;
      #pragma data_seg()
   #endif

I would like to modify HB_MSC_STARTUP code to be more general so
it can be used also with OpenWatcom and maybe some other C compilers
in the future.
I would like to create sth like:

   #elif defined( HB_DATASEG_STARTUP )
      #if defined( HB_DATASEG_INIT )
         #pragma section( HB_STARTUP_SEGMENT, long, read )
      #endif
      #pragma data_seg( HB_STARTUP_SEGMENT )
      #pragma off (unreferenced)    /* to disable unused variable warnings */
      HB_DATASEG_FUNC( init_func )
      #pragma on (unreferenced)     /* to enable unused variable warnings */
      #pragma data_seg()
   #endif

and I need to know if MSC supports:
      #pragma off (unreferenced)    /* to disable unused variable warnings */
      #pragma on (unreferenced)     /* to enable unused variable warnings */
or at least silently ignores them.

Can someone using MS[V]C check it?


Unlike #pragma startup <funcname> this initialization does not use
<funcname> in #pragma directive so we can also store above definition
in single header file hbiniseg.h and then use in other code:

   #elif defined( HB_DATASEG_STARTUP )
      #define HB_DATASEG_BODY HB_DATASEG_FUNC( init_func )
      #include "hbiniseg.h"
   #endif

Such solution will resolve the problem with updating many different files
when we want to make some modifications in data segment based startup code.
Viktor what do you think about it?

best regards,
Przemek
_______________________________________________
Harbour mailing list (attachment size limit: 40KB)
Harbour@harbour-project.org
http://lists.harbour-project.org/mailman/listinfo/harbour

Reply via email to