cond. op. on ='s LHS

Richard Harter rh at smds.UUCP
Mon Feb 18 17:29:37 AEST 1991


In article <15227 at smoke.brl.mil>, gwyn at smoke.brl.mil (Doug Gwyn) writes:
> In article <326 at smds.UUCP> rh at smds.UUCP (Richard Harter) writes:
> >> - >       *(a==b?&c:&d) = 1;
> >Seriously, there is a germ of a good idea here.

> There are good ways of exploiting the ?: operator and bad ways.
> The example being discussed is clearly among the latter.

I agree that the example is a bad idea -- of using the ?: operator
in C.  For that matter the ?: operator is one of the uglier things in
C.  What the chap was doing was emulating a feature that is not in C
or in most other languages, i.e. selected assignment.  The idea is
interesting although I am not sure it is worthwhile.  For example you
can do something like this is in C:

static int a,b,c,d;
static int *index[4] = {&a,&b,&c,&d};
	....
	*index[i] = some-expression;

which is a round-about way of saying "set the i'th item in the list
a,b,c,d to 'some-expression'".  The point is that the example is an
attempt to do something which C does not provide a natural way of doing.
-- 
Richard Harter, Software Maintenance and Development Systems, Inc.
Net address: jjmhome!smds!rh Phone: 508-369-7398 
US Mail: SMDS Inc., PO Box 555, Concord MA 01742
This sentence no verb.  This sentence short.  This signature done.



More information about the Comp.lang.c mailing list