home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / std / c / 3446 < prev    next >
Encoding:
Text File  |  1993-01-29  |  1.6 KB  |  42 lines

  1. Path: sparky!uunet!ukma!gatech!concert!duke!dsb
  2. From: dsb@duke.cs.duke.edu (D. Scott Bigham)
  3. Newsgroups: comp.std.c
  4. Subject: sizeof(size_t) == sizeof(ptrdiff_t) required?
  5. Message-ID: <728279270@majors4.cs.duke.edu>
  6. Date: 29 Jan 93 03:47:51 GMT
  7. Organization: n. Arrangement in an orderly or logical fashion.  See "miracle".
  8. Lines: 32
  9.  
  10. A friend of mine maintains a freeware C compiler -- non-conforming,
  11. unfortunately.  In a recent discussion, he commented that one of the
  12. ways in which his compiler is non-conforming is that sizeof(size_t)
  13. does not equal sizeof(ptrdiff_t) (in particular, sizeof(size_t)=2 and
  14. sizeof(ptrdiff_t)=4).
  15.  
  16. Now, I haven't a copy of the Standard, but I can find no wording in K&R2
  17. to this effect.  I can argue convincingly that sizeof(ptrdiff_t) must be
  18. at least as large as sizeof(size_t); the declaration:
  19.  
  20. char a[N];
  21.  
  22. is legal for any N in the range of a size_t, and the value &a[N]-&a[0]
  23. must be representable for all such N.  I cannot, however, come up with
  24. a plausible reason why sizeof(ptrdiff_t) could not be greater than
  25. sizeof(size_t).  Given:
  26.  
  27. char *a, *b;
  28.  
  29. if the value (b-a) is not in the representable range of a size_t, then
  30. by definition a and b do not point into the same object; the compiler is
  31. not obliged to do anything sensible in this case, but it may certainly
  32. choose to do so.
  33.  
  34. Opinions?  Does the Standard specify this?
  35.  
  36.                         -sbigham
  37. -- 
  38. Scott Bigham                   | The opinions expressed above are
  39. dsb@romeo.cs.duke.edu          | (c) 1993 Hacker Ltd. and cannot be
  40. bigham@hercules.acpub.duke.edu | copied or distributed without a
  41.     (but not for long)         | Darn Good Reason(tm).
  42.