A question of style

Conor P. Cahill cpcahil at virtech.uucp
Mon Dec 4 14:23:17 AEST 1989


In article <22139 at brunix.UUCP>, gvr at brunix (George V. Reilly) writes:
> Because of the two uses of the comma as a parameter separator and as a
> sequential-expression separator, you can occasionally get unexpected
> results.  Consider:
> 
> #define single(list) printf list
> #define double(list) printf(list)
> 
> main()
> {
> 	single("%d %d %d", 1, 2, 3);
> 	double("%d %d %d", 1, 2, 3);
> }
> 
> The expansion of |single()| will yield |printf("%d %d %d", 1, 2, 3)|, while
> the expansion of |double()| will yield |printf(("%d %d %d", 1, 2, 3))|.

This is only true if they were called as follows:

  	single(("%d %d %d", 1, 2, 3));
  	double(("%d %d %d", 1, 2, 3));

which is one of the reasons that I dislike cpp not being able to handle 
a variable number of arguments to a macro (because it forces people to 
think up this solution, or to make up different macros for different numbers 
of arguments).



-- 
+-----------------------------------------------------------------------+
| Conor P. Cahill     uunet!virtech!cpcahil      	703-430-9247	!
| Virtual Technologies Inc.,    P. O. Box 876,   Sterling, VA 22170     |
+-----------------------------------------------------------------------+



More information about the Comp.lang.c mailing list