Re: ## issue with glib.h



Darin Adler <darin@eazel.com> writes:
> The newest version of gcc seems to be more picky about token pasting.
> Incorrect uses of "##" now cause warnings. I've fixed a problem with the use
> of "##" in ORBit. (I don't have the new compiler install myself; I was
> working with some hackers trying to get things to compile on their system.)
> 
> It seems that the use of "##" in front of "args" in the g_error, g_message,
> g_warning, and g_critical macros is also causing this warning. It's
> possible, but unlikely, that the problem is simply that there needs to be a
> space in front of the comma before "##args" (to match the example shown in
> the gcc documentaiton). Or it could be that there's a bug in the picky code
> in the new gcc.
> 
> Since this problem creates an incompatibility between glib.h and the new
> gcc, I thought one of the glib maintainers might want to look into this.

There are two '##' usages that are affected by changes in GCC.

1. Unnecessary token pasting -- rather: pasting generates invalid
   tokens, and the token pasting was unnecessary anyway.

   One instance that I fixed it was in ORBit/src/IIOP/iiop-encoders.h

    -giop_encoder_##typename##(send_buffer, mem)
    +giop_encoder_##typename(send_buffer, mem)

2. Vararg macros.  GNU CC has an additional (deprecated) style as
   compared to ISO C 1999.

   Deprecated GCC way (used in glib.h):
     #define g_message(format, args...) g_log(DOM, LOG_LEV, format, ##args)

   ISO C 1999 way:
     #define g_message(format_args...) g_log(DOM, LOG_LEV, format_args)

   The problem the '##' solves in the first (deprecated) style is when
   args is empty -- in which case it swallows the preceding ',', IOW
   it allows g_message("abc") rather than forcing g_message("abc",).

   The second style is supported in GCC too (well, I checked GCC
   2.7.2.3, and it worked).  So, we should probably just move to that,
   and maybe relax the #ifdef to include ISO C99.

- Hari
-- 
Raja R Harinath ------------------------------ harinath@cs.umn.edu
"When all else fails, read the instructions."      -- Cahn's Axiom
"Our policy is, when in doubt, do the right thing."   -- Roy L Ash




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]