From: Michal Jaegermann <michal@ellpspace.math.ualberta.ca>
To: axp-list@redhat.com
Subject: Re: ccc error
Date: Tue, 9 Jan 2001 09:35:04 -0700 [thread overview]
Message-ID: <20010109093504.A2754@ellpspace.math.ualberta.ca> (raw)
In-Reply-To: <20010109104941.A23344@twister.gmd.de>; from Georg Wittig on Tue, Jan 09, 2001 at 10:49:41AM +0100
On Tue, Jan 09, 2001 at 10:49:41AM +0100, Georg Wittig wrote:
> jeff.sturm@appnet.com wrote:
>
>
> > Does anyone know if the following is valid C:
> >
> > extern int a;
> > extern int b;
> >
> > void f(int x) {
> > (x ? a : b) = 1;
> > }
>
>
> (OT, because this question has nothing to do with axp)
>
> Don't know if it's valid C.
No, it is not. gcc has a number of extentsions. In particular it
will accept expressions as "lvalues" ("lvalue", in short, is something
which can show up on the left hand side of an assignment).
'info gcc' and try to find 'Lvalues' under 'C Extensions'.
> But remember you can always write this as
> * (x? &a : &b) = 1;
This should have the same problem as the above but if you will expand
it to
int *p = (x? &a : &b) ; *p = 1;
which is really the same thing (and probably will compile to the
same code as the original '(x ? a : b) = 1;'), and is valid C.
What is wrong with
void f(int x) {
if (0 != x)
a = 1;
else
b = 1;
}
You can even squish that into a one line if you really want to. :-)
BTW, 'if(x)' will earn you moanings from gcc; you would have to write
'if((x))' if you are (mis)saving on an explicit test.
Michal
next prev parent reply other threads:[~2001-01-09 16:35 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <Pine.LNX.4.10.10101090204570.19797-100000@cc42593-a.taylor1.mi.home.com>
2001-01-09 7:26 ` ccc error jeff.sturm
2001-01-09 9:49 ` Georg Wittig
2001-01-09 9:58 ` Uncle George
2001-01-09 16:35 ` Michal Jaegermann [this message]
2001-01-09 13:51 ` Greg Lindahl
2001-01-09 13:59 ` Thomas Leitner
2001-01-09 16:51 ` Jeff Sturm
2001-01-09 18:05 ` ccc error [OT] Chris Eleveld (Sector 7 Group)
2001-01-09 18:20 ` Michal Jaegermann
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox