home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / std / c / 3208 < prev    next >
Encoding:
Internet Message Format  |  1992-12-14  |  1.2 KB

  1. Path: sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!swrinde!cs.utexas.edu!natinst.com!natinst.com!not-for-mail
  2. From: erik@natinst.com (Erik Crank)
  3. Newsgroups: comp.std.c
  4. Subject: Contradiction wrt arrays
  5. Date: 14 Dec 1992 16:32:59 -0600
  6. Organization: National Instruments, Austin, TX
  7. Lines: 31
  8. Message-ID: <1gj22rINNe9d@falcon.natinst.com>
  9. NNTP-Posting-Host: falcon.natinst.com
  10.  
  11.  
  12. I'm wondering about an apparent contradiction in the standard
  13. concerning addressing "one past the last element" of an array.
  14.  
  15. Consider the following expressions:
  16.     {
  17.         char a[N];
  18.  
  19. (1)     &a[N];
  20. (2)     a[N];
  21.     }
  22.  
  23. If expression (1) is legal (which is implied by the Rationale 3.3.6)
  24. then I claim that expression (2) should also be legal, although it
  25. isn't according to the standard (3.3.6).
  26.  
  27. My reasoning is as follows:
  28.         1. &a[N] is valid iff &(*(a+N)) is valid.
  29.            (by definition of array subscripting [3.3.2.1])
  30.  
  31.         2. &(*(a+N)) is valid iff *(a+N) is valid.
  32.            (by definition of indirection operator [3.3.3.2])
  33.  
  34.         3. *(a+N) is valid iff a[N] is valid.
  35.            ([3.3.2.1])
  36.         ---------------------
  37.         4. &a[N] is valid iff a[N] is valid. (by 1,2,3)
  38.  
  39.  
  40. By "is legal" I mean "has defined behavior".
  41.  
  42.