After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 696504 - RFC: #pragma-less constructors
RFC: #pragma-less constructors
Status: RESOLVED OBSOLETE
Product: glib
Classification: Platform
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2013-03-24 19:00 UTC by Allison Karlitskaya (desrt)
Modified: 2018-05-24 15:04 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Allison Karlitskaya (desrt) 2013-03-24 19:00:14 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?
Comment 1 The Written Word 2016-03-13 21:25:29 UTC
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.
Comment 2 GNOME Infrastructure Team 2018-05-24 15:04:43 UTC
-- 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.