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 364672 - fix macros to follow C syntax rules
fix macros to follow C syntax rules
Status: RESOLVED WONTFIX
Product: glib
Classification: Platform
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2006-10-24 11:17 UTC by Tim Janik
Modified: 2017-10-06 11:04 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Tim Janik 2006-10-24 11:17:45 UTC
GLib provides several macros that are used in ways which conflict with basic C syntax rules. for instance variable and function prototypes declarations roughly obey this syntax:

  TYPE_KEYWORDS FUNCTION_NAME '(' ARGUMENTS ')' ';'
  TYPE_KEYWORDS VARIABLE_NAME [ '=' INITIALIZER ] ';'

intermixing source files with statements like
  G_BEGIN_DECLS
  G_DEFINE_TYPE(someargs)
without a trailing semicolon confuses various non-compiler tools that need to operate on source in non-preprocessed form.
examples here are:
- editors with auto indentation features
- editors or viewers with syntax highlighting features
- indent
- documentation extraction tools like doxygen or c2man
- C->xxx language translators
- C code parsers for introspection needs
- probably other C code parsing tools

for reference, this topic was initially rasied and discussed in bug 351741.
a proper solution was also presented in that bug report, that is the use of macros like:
  #define G_EXTERN_C_BEGIN() extern "C" { /*}*/ void g_dummy_prototype(void)
  #define G_EXTERN_C_END()   /*{*/ }            void g_dummy_prototype(void)
which make use of the declaration
  gthread.h:extern void glib_dummy_decl (void);
which can be found in glib headers since 1.2 days, exactly for the purpose of allowing/enforcing extra semicolons in macro definitions.

unfortunately, some of the macros in quesiton like G_BEGIN_DECLS are in wide spread use, so fixing this will require a somewhat lengthy deprecation process where at first alternative macros are provided that *require* trailing semicolons, and then the original macros are deprecated. due to proper namespacing, the macros names are globally unique however, which means simple search+replace scripts can be provided to simplify the transition process.
Comment 1 Philip Withnall 2017-10-06 11:04:48 UTC
I’d rather the tools were fixed to accept any valid non-preprocessed C code, than have us try and work around it by changing all our (very widespread in use) macros. I think that in the last 11 years, the tools do seem to have got better at this.