Garrett D'Amore wrote: > Christian Kaiser wrote: >> Hi all, >> >> I have a problem with the Sun Studio Express C pre-processor handling >> variadic macros. Look at the following code example: >> >> > 1 #define OSIF_WARN( fmt, args... ) osif_warn(fmt, ## args) >> > 2 >> > 3 void osif_warn(char *fmt, ... ) >> > 4 { >> > 5 } >> > 6 >> > 7 int main (void) >> > 8 { >> > 9 osif_warn("%s", "bla"); >> > 10 OSIF_WARN("%s", "bla"); >> > 11 osif_warn("blu"); >> > 12 OSIF_WARN("blu"); >> > 13 return 0; >> > 14 } >> >> The pre-processor throws a warning: "varargs.c", line 12: warning: >> argument mismatch >> >> Although, the code the pre-processor (cc -E) generates looks good! >> >> > int main (void) >> > { >> > osif_warn("%s", "bla"); >> > osif_warn ( "%s" , "bla" ); >> > osif_warn("blu"); >> > osif_warn ( "blu" ); >> > return 0; >> > } >> >> Why does the sun-cpp generate a warning even though the code looks >> good? It seems that the sun-cpp is not able to handle variable >> argument lists with zero entries! Is this a bug then? >> > > No. The C99 standard specifies that for variadic macros you must > include at least one argument in the arguments being pasted by the CPP. > > So, what you have to do is include the *format* in the first the arg, so > you have: > > #define OSIF_WARN(args...) osif_warn(__VA_ARGS__) > > Then the __VA_ARGS__ will include the format. There's a description here: > > http://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html > > -- Garrett >
OK, thank you! That helped to solve my problem. I was confused by the fact that the same code was no problem for the GNU cpp. But that is also explained on the page you sent. The GNU cpp violates the C99 standard in our case. >> I am using cc: Sun Ceres C 5.10 SunOS_i386 2008/04/04 of the >> "sunstudioexpress" package for OpenSolaris 2008.05. >> >> Regards, >> Christian >> >> > -- Christian Kaiser, Software Engineer, Dolphin Interconnect Solutions http//www.dolphinics.com _______________________________________________ opensolaris-code mailing list opensolaris-code@opensolaris.org http://mail.opensolaris.org/mailman/listinfo/opensolaris-code