home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!uunet.ca!canrem!dosgate!dosgate![peter.curran@canrem.com]
- From: "peter curran" <peter.curran@canrem.com>
- Subject: question to test general
- Message-ID: <1992Dec19.4396.29898@dosgate>
- Reply-To: "peter curran" <peter.curran@canrem.com>
- Organization: Canada Remote Systems
- Distribution: comp
- Date: 19 Dec 92 09:40:38 EST
- Lines: 50
-
- dkeisen@leland.Stanford.EDU (Dave Eisen) writes...
-
- ...
- DE>I can't think of a legitimate reason why you'd want to use x[y] where
- DE>x is an integer and y a pointer. And a compiler is certainly capable
- DE>of checking types before it replaces x[y] with *(x + y). Or is there
- DE>a reason, other than the obvious need for fodder for Obfuscated C
- DE>contests, why this construct should be in the language?
-
- The simplest explanation for this is that it was a standard
- construct in B, the predecessor of C, and carrying it across to the
- new language no doubt helped facilitate the original acceptance of C.
-
- B did not have structs or pointers. (Originally C did not have
- structs either.) One simulated structures with something like this:
-
- #define FIELD1 0 /* Define the fields. All are words. */
- #define FIELD2 1 /* B had no types. */
- #define FIELD3 2
-
- (I don't think that was the syntax for a macro, but I don't
- remember exactly.)
-
- To allocate a structure, an array of the appropriate size was
- declared:
-
- x[3];
-
- Finally, field references were done with expressions such as
-
- FIELD1[x]
-
- Actually, x[FIELD1] would have worked just as well, but the former
- syntax became conventional, to emphasize that one was working with
- structures, not arrays.
-
- There are several features of C that are carry-overs from B (the
- most obvious is the useless keyword "auto") that were no doubt
- included to help in porting software, to encourage acceptance of C.
- C was a lot more B-like originally, but a lot of the rough edges
- that resulted from that have been cleaned up over the years.
- A few still remain.
-
- Peter Curran
- Usenet: peter.curran@canrem.com RIME: CRS (#118)
- ---
- ■ DeLuxe² 1.25 #12339 ■
- --
- Canada Remote Systems - Toronto, Ontario
- World's Largest PCBOARD System - 416-629-7000/629-7044
-