[net.unix-wizards] C oddity -- language and/or compiler

smb (01/19/83)

A co-worker found this one the hard way....

	double	a;	/* Note the semi-colon! */
		b,
		c,
		d;
	main()
	{
		a = b;
	}

On the VAX, this program was silently accepted, and b, c, and d were
assigned 4 bytes apiece.  On an 11, using the Ritchie C compiler, *nothing*
was generated for b, c, and d; pcc, however, behaved the same way it did on
the VAX.

Presumably, we have some sort of bug here, since two different C compilers
are doing very different things.  My take is that both are wrong; that that
construction should be flagged as a syntax error.  But I'm willing to be
convinced that we've stumbled across another strange and wondrous property of
the comma operator.

Enlightenment, anybody?

		--Steve Bellovin
		{rabbit,mhb5b,mhb5c}!smb

mat (01/20/83)

I have some speculation on the behavior of the compilers, but no REAL answers.
Here's another PCC peculiarity that someone discovered recently:
struct
{
	....;
	....
	....
} xyz;
struct	xyz Xyz;
main()
{
	....
	many references to xyz, none to Xyz;
}
The PCC repeorted NO errors, the Ritchie compiler correctly tagged the
	struct xyz Xyz;
as an undefined structure `xyz' .
Speculation: The PCC would have checked the validity of the structure
definition when a reference was found to that structure.
	Perhaps Dennis and Steve Johnson would like to explain this
apparently anomalous behavior?

			hou5a!mat