home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / c / 16678 < prev    next >
Encoding:
Text File  |  1992-11-17  |  2.3 KB  |  50 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!ukma!darwin.sura.net!zaphod.mps.ohio-state.edu!uunet.ca!wildcan!sq!msb
  3. From: msb@sq.sq.com (Mark Brader)
  4. Subject: Re: Idle Questions about ANSI C
  5. Message-ID: <1992Nov17.155826.15087@sq.sq.com>
  6. Organization: SoftQuad Inc., Toronto, Canada
  7. References: <1992Nov13.213708.5456@mccc.edu> <BxqBp1.5M6@netnews.jhuapl.edu> <1992Nov17.123803.6400@thunder.mcrcim.mcgill.edu>
  8. Date: Tue, 17 Nov 92 15:58:26 GMT
  9. Lines: 39
  10.  
  11. > > According to K+R 2nd ed, section A7.4.8, size_t is "an unsigned
  12. > > integral constant; the particular type in implementation defined".
  13. > Well, the result of sizeof is the quoted thing, and it notes that
  14. > <stddef.h> defines the type in question as size_t.
  15. > Now: is it required that size_t be the same as one of the four usual
  16. > unsigned integral types?  (How about ptrdiff_t?)
  17.  
  18. The wording of section 3.1.2.5/6.1.2.5 of the standard clearly implies
  19. that the 9 "usual" integral types are the only ones.  They consist of
  20. 4 signed integer types, 4 unsigned integer types, and char -- which
  21. of course can be either signed or unsigned.  Since size_t and ptrdiff_t
  22. are specified respectively as unsigned or signed *integral* types, not
  23. *integer* types, then an implementation could actually use char for
  24. one of them -- remember, it could be the same size as int or even long.
  25. So there are 5 possibilities for each.
  26.  
  27. There *are* implementations that define extra integral types -- the
  28. appendix even mentions this as a common extension.  However, I don't
  29. see how an implementation could be conforming if it made size_t, say,
  30. a type that was longer than long.
  31.  
  32. Threads that are purely about ANSI C, as this one is according to its
  33. subject line, are better placed in comp.std.c.  If someone wants to
  34. dispute the above conclusions in terms of the standard, I suggest they
  35. crosspost to comp.std.c and direct followups there.
  36.  
  37. A side remark since I *am* writing in comp.lang.c.... the computer on
  38. which I'm typing this has a pre-ANSI implementation in which size_t
  39. is provided, not in one of the standard C headers, but in the UNIX
  40. header <sys/types.h> ... and size_t is *int*.  And in fact sizeof
  41. appears to return int also; at least, "sizeof(char) < -1" is false,
  42. whereas in ANSI C it's true.
  43. -- 
  44. Mark Brader, SoftQuad Inc., Toronto, utzoo!sq!msb, msb@sq.com
  45. #define    MSB(type)    (~(((unsigned type)-1)>>1))
  46.  
  47. This article is in the public domain.
  48.