K&R is not the bible

G. Bogatko cim1 at pyuxv.UUCP
Tue Feb 25 10:32:54 AEST 1986


	There is an awful lot of refering to K&R as if it were a bible of C
syntax.  Now I will admit that It contains an awful lot about what C is, and
that it was authored by the guy that invented the language, but listen
folks, it was written in 1978, and we just can't keep thinking that C begins
and ends with K&R.

	For example, if I call a compiler company and ask them
 if their compiler supports enums and structure passing, I will most likely
 get the answer,

	"Well, that sort of stuff is not K&R, so we don't do it."

Well, it might not be K&R, but it IS legal C. Not only that but it's been
around since 1978.  Listen to the Seventh Edition UNIX Manual (if UNIX C
isn't a benchmark, then what is?)

	Page 277:

			Recent Changes to C

			 November 15, 1978

A few extensions have been made to the C language beyond what is described
in the reference document("The C Programming Language," Kernighan and
Ritchie, Prentice-Hall, 1978)

1. Structure assignment

	Structures may be assigned, passed to functions, and returned by
functions.

2. Enumeration type

	There is a new data type analogous to the scalar types of Pascal.
[continues with a description of enums]

***********************

I've been told, but I haven't personally seen it, that Ritchie brought out a
new version of the reference manual in 1980 that included struct passing and
enums.

You can't tell me that 8 years is not enough time for this kind of change to
get out. (I know, Microsoft 3.0 C does it, and I think also CI, but this
is only recently).

Enough then.  K&R is OLD.  It is NOT the alpha and omega of C. When I want
to see what C is doing NOW, I refer to books that are more contemporary.

***********************

K&R:	"In evalulating a[i], C converts it to *(a+i) immediately"

Therefore, is a[x] the same as x[a]?  It is on UNIX C and AZTEC C. It isn't on
MICROSOFT C.  Try this on your compiler:

#include <stdio.h>
main()
{
static char a[] = "abcdefg";

	putchar(a[3]);
	putchar(3[a]);

	putchar("xyzq1234"[4]);		/* does this work on your compiler? */
	putchar(4["xyzq1234"]);		/* does this? */
					/* they work on UNIX */
}

What is the standard here?

If K&R doesn't mention this kind of thing specifically, does it mean that the
implementations that allow it are wrong?  How about the ones don't allow it.
Are they wrong too?

G. Bogatko



More information about the Comp.lang.c mailing list