grahamr (01/19/83)
PCC goes along with the reference manual where the Ritchie compiler doesn't. I don't have a white book page number, but in section 10 of the paper "The C Programming Language -- Reference Manual" (I think this paper appears as an appendix to the white book), note: A C program consists of a sequence of external definitions. An external definition declares an identifier to have storage class extern (by default) or perhaps static, and a specified type. The type-specifier (sec. 8.2) may also be empty.... Also, note that in the entries in the syntax summary (sec. 18.4) the only part of these external definitions that is required is the semicolon! program : external-definition external-definition : data-definition data-definition : EXTERN[opt] type-specifier[opt] init-declarator-list[opt] ; PCC is the only compiler I know of which actually performs correctly. Your example: double a; b,c,d; declares a to be "extern double" and b, c, and d to be "extern int". In the VAX code for "main(){a=b;}" note that an integer-to-floating conversion is done: _main: .word L16 cvtld _b,r0 movd r0,_a ret - Graham Ross, Tektronix
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
johnl (01/21/83)
#R:rabbit:-106700:ima:15900001:000:414 ima!johnl Jan 20 11:03:00 1983 What we have here is perfectly legal C. double a; /* Note the semi-colon! */ b, c, d; In external declarations, all of the specifiers are optional so that foo; defines foo to be, by default, "extern int foo;". I agree it's silly and perhaps should be illegal (or at least provoke a complaint from lint) but it's legit now. John Levine, decvax!yale-co!jrl, ucbvax!cbosgd!ima!johnl, research!ima!johnl