Path: utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!aurs01!throop From: throop@aurs01.UUCP (Wayne Throop) Newsgroups: comp.lang.c Subject: Re: cond. op. on ='s LHS Message-ID: <59582@aurs01.UUCP> Date: 18 Feb 91 16:37:12 GMT References: <326@smds.UUCP> <15227@smoke.brl.mil> <1196@sheol.UUCP> <15231@smoke.brl.mil> Sender: news@aurs01.UUCP Lines: 44 > gwyn@smoke.brl.mil (Doug Gwyn) [.. discussing *(a==b?&c:&d) = 1 ..] > It is an abuse of the potential utility of the ?: operator to use it, > especially with the addition of levels of indirection, where a simple > if ( a == b ) c = 1; else d = 1; > would be much clearer [...] clarity is very important. I agree strongly about the general principle of clarity. But I suspect I may differ in the question of what is clear. To start with agreement, I agree about the extra levels of indirection being unclear. For example, *(color==BLUE? &blue_items : &nonblue_items) += 1; is more messy (and less to be prefered) than if( color==BLUE ) blue_items += 1; else nonblue_items += 1; Worse still, the former requires mumble_items to be addressable, when they conceptually only need to be lvalues. But on the other hand, I'd say that the GCC extension (color==BLUE ? blue_items : nonblue_items) += 1; is clearer than either, and something like *(color==BLUE ? blue_items_ref : nonblue_items_ref) += 1; seems perfectly clear to me, and (as a matter of taste) preferable to the use of an "if" statement (say, inside a routine which counts item colors as a side effect and is passed references to counts to fill in (uh... not that I'd tend to design a routine that way, but supposing someone did...)). Certainly (hmmm... better say "IMHO"), it isn't much less clear than item_count[color] += 1; Wayne Throop ...!mcnc!aurgate!throop