When is a statement an expression?

David Goodenough dg at lakart.UUCP
Sat Apr 29 02:18:11 AEST 1989


scs at vax3.iti.org (Steve Simmons) sez:
> ......
> we wrote code like:
> 
> main()
> {
> 	int a = 0 ;
> 
> 	a = if ( a == 1 )
> 		12 ;
> 	else
> 		14 ;
> 	printf( "Value of a is %d\n", a ) ;
> }

UUMMPHFF!!!! When did C compilers learn to talk ALGOL. Either that or it's
a funky way of doing:

	a = (a == 1) ? 12 : 14;

from a somewhat odd compiler.

> We tried it out on all the C compilers we could find (BSD 4.3, Gould,
> UNIX-PC, gcc) and it fails.

I'm not in the least surprised - C was never specified to do that.

> But the error messages are quite cryptic
> (we like gcc: "parse error after 'a'") and largely don't address
> the real problem.

Basically the syntax is totally out to lunch, and different parsers will
decide that different errors exist.

> Anybody else ever use stuff like this?

Not a chance - it's not legal C.
-- 
	dg at lakart.UUCP - David Goodenough		+---+
						IHS	| +-+-+
	....... !harvard!xait!lakart!dg			+-+-+ |
AKA:	dg%lakart.uucp at xait.xerox.com		  	  +---+



More information about the Comp.lang.c mailing list