Checksum: 24076 Lines: 39 Path: utzoo!sq!msb From: msb@sq.uucp (Mark Brader) Date: Tue, 12-Apr-88 13:51:41 EDT Message-ID: <1988Apr12.135141.3122@sq.uucp> Newsgroups: comp.lang.c Subject: #if sizeof(int) References: <10949@mimsy.UUCP> <1525@dataio.Data-IO.COM> <7637@brl-smoke.ARPA> <10353@steinmetz.ge.com> Reply-To: msb@sq.UUCP (Mark Brader) Organization: SoftQuad Inc., Toronto > 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 since parentheses are required around type names and the result of sizeof is in bytes. Yes, I'd like this too. But in the (draft) ANSI C environment, you can get the same information another way: #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.) > ... > #define INT long > #else > #define INT int > #endif 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. [Yes, there are reasons why one might want to change types according to the machine's type sizes. The above, however, does not seem to be one of them.] Mark Brader "A hundred billion is *not* infinite SoftQuad Inc., Toronto and it's getting less infinite all the time!" utzoo!sq!msb, msb@sq.com -- Isaac Asimov, "The Last Question"