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