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

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!enterpoop.mit.edu!bloom-picayune.mit.edu!news
  3. From: scs@adam.mit.edu (Steve Summit)
  4. Subject: Re: Exact-sized types
  5. Message-ID: <1992Dec13.215723.27091@athena.mit.edu>
  6. Sender: news@athena.mit.edu (News system)
  7. Nntp-Posting-Host: adam.mit.edu
  8. Organization: none, at the moment
  9. References: <1992Nov30.204147.7955@cimage.com> <84931@ut-emx.uucp> <1992Dec8.174127.3244@thunder.mcrcim.mcgill.edu>
  10. Date: Sun, 13 Dec 1992 21:57:23 GMT
  11. Lines: 43
  12.  
  13. In article <1992Dec8.174127.3244@thunder.mcrcim.mcgill.edu>, mouse@thunder.mcrcim.mcgill.edu (der Mouse) writes:
  14. > In article <84931@ut-emx.uucp>, jamshid@ut-emx.uucp (Jamshid Afshar) writes:
  15. >> I don't understand the purpose of the "at-least-N-bits" types.  C
  16. >> already has those -- char (>=8), short (>=16), int (>=16), and long
  17. >> (>=32).  What does your extra level of indirection buy you?
  18. > Suppose I need at-least-20-bits.  If I follow your advice, I have to
  19. > simply use long int.  However, when porting to a machine with 32-bit
  20. > ints and 64-bit longs, this wastes lots of space...
  21. > It might also be reasonable to have different types optimized for speed
  22. > and space: "atleast20b_fast" and "atleast20b_small"...
  23.  
  24. I suppose that in an ideal world we'd have a popular language
  25. which gave us this kind of fine control in declarations and yet
  26. did not have a few of PL/I's other problems.
  27.  
  28. It's safe to say that the number of times one actually needs a
  29. 20-bit type is greatly exceeded by the number of times unwitting
  30. programmers use int16 and the like and end up diminishing the
  31. maintainability of their programs.  (For example: how do you
  32. printf an atleast20b_small? [1])
  33.  
  34. Nine times out of ten [2], advice such as Jamshid's is entirely
  35. appropriate.
  36.  
  37.                     Steve Summit
  38.                     scs@adam.mit.edu
  39.  
  40. Note 1.  The answer, of course, is
  41.  
  42.     atleast20b_small x;
  43.     printf("%ld\n", (long int)x);
  44.  
  45. , but nine times out of ten this will instead be written as
  46.  
  47.     printf("%ld\n", x);
  48. or
  49.     printf("%d\n", x);
  50.  
  51. , depending on the definition of the atleast20b_small type on the
  52. initial development machine.
  53.  
  54. Note 2.  possibly much higher.
  55.