Path: utzoo!attcan!uunet!brunix!gvr From: gvr@brunix (George V. Reilly) Newsgroups: comp.lang.c Subject: Re: A question of style Summary: Oops! Typos! Message-ID: <22150@brunix.UUCP> Date: 4 Dec 89 03:33:29 GMT References: <547@mars.Morgan.COM> <1989Nov30.001947.14883@aqdata.uucp> <3552@convex.UUCP> <22139@brunix.UUCP> Sender: news@brunix.UUCP Reply-To: gvr@panda.UUCP (George V. Reilly) Organization: Brown University Department of Computer Science Lines: 33 In article <22139@brunix.UUCP> gvr@panda.UUCP (George V. Reilly) [I] wrote: : 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))|. : The argument to the second printf will be treated as four comma-separated : expressions which evaluate to the last expression (3), ultimately : yielding |printf(3)|, which will probably cause a segmentation fault : and a core dump. That's what happened to me the other day, at least. Oops, I goofed. There should have been two sets of parentheses each for the invocations of |single()| and |double()|, thus: single(("%d %d %d\n", 1, 2, 3)); double(("%d %d %d\n", 1, 2, 3)); Thanks to Rich Salz for pointing out that my original posting got argument-mismatch errors from cpp. ------ George V. Reilly gvr@cs.brown.edu uunet!brunix!gvr gvr@browncs.bitnet Box 1910, Brown U, Prov, RI 02912