>>>>> "jaroslav" == Jaroslav Kysela <[EMAIL PROTECTED]> writes:

jaroslav> On 8 Nov 2001, Juan Quintela wrote:
>> 
>> Hi
>> this patch fixes the abuse of ## in alsa sources.  It was used
>> in ways that are not documented to work.  It changes all the
>> apparitions to ways that work in all the compilers and do what they
>> are expected to do, changes are code of the form:
>> 
>> #define FOO(args...)        printk(bar, ##args)
>> 
>> correct writting is:
>> 
>> #define FOO(format, args...)        printk(bar, foo, ##args)
>> 
>> Notice that this is abused also in other creative ways, all the uses
>> are changed to follow this last construct that is documented to work
>> in last ANSI standard (and gcc documentation by the way).
>> 
>> gcc-2.96 & gcc-3.0 don't like that construct, and notice that this was
>> not valid C in the first place.  Resulting code compile also witohut
>> errors with egcs-1.1.2.

jaroslav> I would recommend to do same change as in the latest alsa drivers:

jaroslav> #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
jaroslav> #define NEW_MACRO_VARARGS
jaroslav> #endif


jaroslav> #ifdef NEW_MACRO_VARARGS

jaroslav> /*
jaroslav> *  VARARGS section
jaroslav> */

jaroslav> #define snd_printk(...) do {\
jaroslav> printk("ALSA %s:%d: ", __FILE__, __LINE__); \
jaroslav> printk(__VA_ARGS__); \
jaroslav> } while (0)


jaroslav> #else

jaroslav> /*
jaroslav> *  Old args section...
jaroslav> */

jaroslav> #define snd_printk(args...) do {\
jaroslav> printk("ALSA %s:%d: ", __FILE__, __LINE__); \
jaroslav> printk(##args); \
jaroslav> } while (0)

jaroslav> #endif

jaroslav> We should retain the compilation compatibility with older GCC as well.
jaroslav> If you send me a patch in this way, I'll apply it.

I can redo that that way if you preffer, but my way was supposed to
work with both compilers, supposed as that I compiled them with
gcc-2.96 & egcs-1.1.2.  Are you talking here of older compilers?

Notice that the problem is not snd_prink(), problem are the code that
does:

#define my_printk(args...)     printk(__FILE__": " ##args)

that is abusing _too_ much the extension.

Looking at gcc documentation, it implies (and testing also confirm
that), that my example works for both gcc versions, older & new.

Cpp->variadic macros

   Previous versions of GNU CPP implemented the comma-deletion extension
much more generally.  We have restricted it in this release to minimize
the differences from C99.  To get the same effect with both this and
previous versions of GCC, the token preceding the special `##' must be
a comma, and there must be white space between that comma and whatever
comes immediately before it:

     #define eprintf(format, args...) fprintf (stderr, format , ##args)

-- 
In theory, practice and theory are the same, but in practice they 
are different -- Larry McVoy

_______________________________________________
Alsa-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/alsa-devel

Reply via email to