home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / c / 18679 < prev    next >
Encoding:
Text File  |  1992-12-21  |  2.1 KB  |  62 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!uunet.ca!canrem!dosgate!dosgate![peter.curran@canrem.com]
  3. From: "peter curran" <peter.curran@canrem.com>
  4. Subject: question to test general
  5. Message-ID: <1992Dec19.4396.29898@dosgate>
  6. Reply-To: "peter curran" <peter.curran@canrem.com>
  7. Organization: Canada Remote Systems
  8. Distribution: comp
  9. Date: 19 Dec 92 09:40:38 EST
  10. Lines: 50
  11.  
  12. dkeisen@leland.Stanford.EDU (Dave Eisen) writes...
  13.  
  14. ...
  15. DE>I can't think of a legitimate reason why you'd want to use x[y] where
  16. DE>x is an integer and y a pointer. And a compiler is certainly capable
  17. DE>of checking types before it replaces x[y] with *(x + y). Or is there
  18. DE>a reason, other than the obvious need for fodder for Obfuscated C
  19. DE>contests, why this construct should be in the language?
  20.  
  21. The simplest explanation for this is that it was a standard
  22. construct in B, the predecessor of C, and carrying it across to the
  23. new language no doubt helped facilitate the original acceptance of C.
  24.  
  25. B did not have structs or pointers.  (Originally C did not have
  26. structs either.)  One simulated structures with something like this:
  27.  
  28. #define FIELD1  0           /* Define the fields.  All are words. */
  29. #define FIELD2  1           /* B had no types.                    */
  30. #define FIELD3  2
  31.  
  32. (I don't think that was the syntax for a macro, but I don't
  33. remember exactly.)
  34.  
  35. To allocate a structure, an array of the appropriate size was
  36. declared:
  37.  
  38. x[3];
  39.  
  40. Finally, field references were done with expressions such as
  41.  
  42. FIELD1[x]
  43.  
  44. Actually, x[FIELD1] would have worked just as well, but the former
  45. syntax became conventional, to emphasize that one was working with
  46. structures, not arrays.
  47.  
  48. There are several features of C that are carry-overs from B (the
  49. most obvious is the useless keyword "auto") that were no doubt
  50. included to help in porting software, to encourage acceptance of C.
  51. C was a lot more B-like originally, but a lot of the rough edges
  52. that resulted from that have been cleaned up over the years.
  53. A few still remain.
  54.  
  55. Peter Curran
  56. Usenet: peter.curran@canrem.com     RIME: CRS (#118)
  57. ---
  58.  ■ DeLuxe² 1.25 #12339 ■ 
  59. --
  60. Canada Remote Systems  - Toronto, Ontario
  61. World's Largest PCBOARD System - 416-629-7000/629-7044
  62.