Bug in cpp macro varargs extension
Kaveh R. Ghazi
ghazi@caip.rutgers.edu
Tue Mar 2 10:19:00 GMT 1999
Does anyone use gcc's macro varargs extension? Is is
considered usable?
I'm having several problems getting correct expansions. I think
it boils down to this test case:
> #define error1(msg, args...) printf(msg, "foo", ## args)
> #define error2(msg, args...) printf("foo", msg, ## args)
>
> main()
> {
> error1("%s, %s", "hello");
> error2("%s, %s", "hello");
>
> error1("%s");
> error2("%s");
> }
Running this through either the current egcs snapshot yields:
> main()
> {
> printf( "%s, %s" , "foo","hello" ) ;
> printf("foo", "%s, %s" ,"hello" ) ;
>
> printf( "%s" , ) ;
> printf("foo", "%s" ) ;
> }
Notice that the 3rd printf is missing an argument. I believe
that whenever the expansion inserts stuff right before the varargs
that's not a macro parameter, it gets lost. But this is only true
if args... evaluates to nothing, as can be seen in the first printf.
Can anyone help with this bug?
Thanks,
--Kaveh
PS: This is with cccp.c, I haven't tried cpplib.
--
Kaveh R. Ghazi Engagement Manager / Project Services
ghazi@caip.rutgers.edu Qwest Internet Solutions
More information about the Gcc-bugs
mailing list