GNOME Bugzilla – Bug 696504
RFC: #pragma-less constructors
Last modified: 2018-05-24 15:04:43 UTC
My preferred solution to bug 627423 involves defining a destructor function from a macro. gconstructor.h says: Some compilers need #pragma to handle this, which does not work with macros, so the way you need to use this is (for constructors): #ifdef G_DEFINE_CONSTRUCTOR_NEEDS_PRAGMA #pragma G_DEFINE_CONSTRUCTOR_PRAGMA_ARGS(my_constructor) #endif G_DEFINE_CONSTRUCTOR(my_constructor) static void my_constructor(void) { ... } Which obviously won't work out for me from a macro. Looking into it, I see two cases that this is actually used: /* Visual studio 2008 and later has _Pragma */ /* Pre Visual studio 2008 must use #pragma section */ and... #elif defined(__SUNPRO_C) #define G_DEFINE_CONSTRUCTOR_PRAGMA_ARGS(_func) \ init(_func) For Visual Studio pre-2008, I see two possible solutions: 1) stop caring 2) Visual Studio is actually a C++ compiler, right? It's pretty easy to get a destructor function called in C++ without using pragmas... For the SUNPRO_C case is it possible that we could use _Pragma? Is this the same as the modern Sun compiler or some old version? Is there another way?
Neither HP-UX nor AIX can use _Pragma. The #define G_DEFINE_CONSTRUCTOR_PRAGMA_ARGS on AIX is similar to the solution for the Sun compiler but not so for HP-UX. There isn't one universal method for constructors/destructors across Solaris, HP-UX, AIX.
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/glib/issues/677.