Mike Frysinger wrote: > On Thursday 21 January 2010 20:21:31 Jamie Lokier wrote: > > Mike Frysinger wrote: > > > GCC-2.x has a bug with empty arg expansion in macros. > > > > > > - fprintf(stderr, "%s:%i: " fmt, __func__, __LINE__, ## args); \ > > > + fprintf(stderr, "%s:%i: " fmt, __func__, __LINE__ , ## args); \ > > > > Assuming it's what it looks like, it's not a GCC-2.x bug, it's the old > > GCC varargs behavior, which was documented and behaved like that since > > very old versions of GCC. > > i'm not really familiar with gcc-2 ... i didnt get into messing with > toolchain > stuff until like gcc-3.4 era.
Wow. I haven't messed much with toolchain stuff since the 2.7.2 era ;-) > it looks like a bug to me as gcc-3+ works fine. > if you wanted to elaborate ... GCC 2.95 documentation: This is a special feature of the GNU C preprocessor: @samp{##} before a rest argument that is empty discards the preceding sequence of non-whitespace characters from the macro definition. (If another macro argument precedes, none of it is discarded.) It might be better to discard the last preprocessor token instead of the last preceding sequence of non-whitespace characters; in fact, we may someday change this feature to do so. We advise you to write the macro definition so that the preceding sequence of non-whitespace characters is just a single token, so that the meaning will not change if we change the definition of this feature. It's behaved like that since the macro varargs feature was introduced in GCC 2.2 (released June 1992), and was consciously changed to in GCC 3.0 (released June 2001). > this one fails: > #define debug(fmt, args...) x(fmt, moo, ## args) > main(){debug("a");} > > these work: > #define debug(fmt, args...) x(fmt, moo , ## args) > main(){debug("a");} > > #define debug(fmt, args...) x(fmt, ## args) > main(){debug("a");} The last one compiles for a surprising reason: fmt is preexpanded to ' "a" ' (complete with spaces), so the word-removal rule goes back as far as the comma and stops at the last space of the preexpanded fmt. Anyway, your patch is fine! :-) Only the commit message is misleading; this would be appropriate imho: GCC-2.x's variadic macro behaviour requires an isolated comma The behaviour of GCC before 3.0 was to remove the whole non-whitespace word prior to ## (after argument expansion), not just the comma. _______________________________________________ uClinux-dev mailing list uClinux-dev@uclinux.org http://mailman.uclinux.org/mailman/listinfo/uclinux-dev This message was resent by uclinux-dev@uclinux.org To unsubscribe see: http://mailman.uclinux.org/mailman/options/uclinux-dev