Path: utzoo!attcan!uunet!virtech!cpcahil From: cpcahil@virtech.uucp (Conor P. Cahill) Newsgroups: comp.lang.c Subject: Re: A question of style Message-ID: <1989Dec4.032317.29614@virtech.uucp> Date: 4 Dec 89 03:23:17 GMT References: <547@mars.Morgan.COM> <1989Nov30.001947.14883@aqdata.uucp> <22139@brunix.UUCP> Organization: Virtual Technologies Inc. Lines: 34 In article <22139@brunix.UUCP>, gvr@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 | +-----------------------------------------------------------------------+