Path: utzoo!mnetor!uunet!steinmetz!davidsen From: davidsen@steinmetz.ge.com (William E. Davidsen Jr) Newsgroups: comp.lang.c Subject: Re: #if sizeof(int) Message-ID: <10425@steinmetz.ge.com> Date: 14 Apr 88 15:47:50 GMT References: <10949@mimsy.UUCP> <1525@dataio.Data-IO.COM> <7637@brl-smoke.ARPA> <10353@steinmetz.ge.com> <1988Apr12.135141.3122@sq.uucp> Reply-To: davidsen@crdos1.UUCP (bill davidsen) Organization: General Electric CRD, Schenectady, NY Lines: 41 In article <1988Apr12.135141.3122@sq.uucp> msb@sq.UUCP (Mark Brader) writes: | | | > With programs traveling | > between 32 bit machines and 16 bit machines (286, 11s) I want to say: | > #if sizeof int < 32 | | Actually, you mean | #if sizeof(int) < 4 As you say... I noticed that about two days after the posting, when it was too late to call it back. | #if INT_MAX < 0x7FFFFFFF | | This is *more* reliable, because it does not assume, as the second version | did, that a byte is 8 bits. That is, your code is more likely to do what | you expect on a machine where chars are 16 bits and ints are 32. (Whether | any such machines now exist is irrelevant; they are allowed.) The problem which comes to mind needs room for 4 characters or 32 bits. dpANS seems to guarantee that a byte will be at least 8 bits, so it works. | But if that's all you want it for, why not just use long in the first place? | With the above, you must write | | printf ("%ld\n", (long) x); | | or some form using conditional-compiled code in the printf() format, | every time you want to print one of these "INT" variables. And similarly | with other library functions. Again, I'm looking at a specific problem, in which I never want to print anything, I just want to create a data structure for flags and a 4 char identifier. You're correct about the cast, although I think I'd use a prototype. -- bill davidsen (wedu@ge-crd.arpa) {uunet | philabs | seismo}!steinmetz!crdos1!davidsen "Stupidity, like virtue, is its own reward" -me