Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Usage of comma operator

Path: gmdzi!unido!mcsun!hp4nl!and!jos
From: j...@and.nl (Jos Horsmeier)
Newsgroups: comp.lang.c
Subject: Re: Usage of comma operator
Message-ID: <1547@baby.and.nl>
Date: 25 Sep 91 07:59:40 GMT
References: <1991Sep19.053910.2431@uokmax.ecn.uoknor.edu> <kdo6miINN5m3@mthvax.cs.miami.edu> <1991Sep24.155000.18359@arcturus.uucp>
Organization: AND Software BV Rotterdam
Lines: 45

In article <1991Sep24.155000.18...@arcturus.uucp> be...@arcturus.uucp (Berry;Craig D.) writes:
|ya...@mthvax.cs.miami.edu (Yanek Martinson) writes:
|
|>In <1991Sep19.053910.2...@uokmax.ecn.uoknor.edu> spcol...@uokmax.ecn.uoknor.edu (Steve Coltrin) writes:
|
[ some stuff deleted ... ]
|
|>x(1,2,3);
|
|>how would this be interpreted? x(1,(2,3)) or x((1,2),3) ???
|
|Congratulations!  You have discovered one of the ugliest warts on the
|otherwise beautiful C language.  Comma has different semantics in
|a function call argument list than elsewhere.  This is similar to the
|way * and & are overloaded as unary and binary operators with totally
|unrelated meanings.  So,
|
|	x(1,2,3);      /* Passes 1, 2, and 3 to x */
|	x((1, 2), 3);  /* Passes 2 and 3 to x     */
|
|Ugly, yet true.  Still, this is probably more of a headache for compiler
|writers than for C users.

Sorry, I don't agree with you. When you look at the grammar rules, page 237
of K&R2 (at least in my copy), you'll find an expression defined as one
or more assignment-exprs, separated by the comma operator. Page 238 shows
an argument expression list defined as one or more assignment-exprs, so 
this comma stuff *is* clearly defined. It is not much of a headache for
compiler writers. 

What I *do* find ugly is something like this:

typedef int T;		/* T is a new type */

int T;			/* Beng! redefinition */

struct T {		/* T is fine as a struct tag ... */
	T T;		/* All's fine in here! */
	...
} T;			/* Beng! redef again! */

Have you ever tried to write a proper lexical analyser for this kludge?
This gave *me* a headache ... name spaces, pfah! 

Jos aka j...@and.nl