Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!ucsd!pacbell.com!decwrl!bacchus.pa.dec.com!deccrl!decvax.dec.com!ima!haddock!karl From: karl@haddock.ima.isc.com (Karl Heuer) Newsgroups: comp.lang.c Subject: Determining machine characteristics (was: IsUnsigned() function?) Message-ID: <17148@haddock.ima.isc.com> Date: 25 Jul 90 01:18:23 GMT References: <1990Jul16.214155.5087@Neon.Stanford.EDU> <2936@mtung.ATT.COM> <1990Jul22.154326.19680@ux1.cso.uiuc.edu> Reply-To: karl@kelp.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Cambridge, MA 02138-5302 Lines: 26 In article <1990Jul22.154326.19680@ux1.cso.uiuc.edu> mcdonald@aries.scs.uiuc.edu (Doug McDonald) writes: >[Assuming the question was to analyze the *type*, can it be done portably?] Already solved, see my earlier post. >To extend it a bit, how about macros for [the format of negative numbers] Assuming there are only the three possibilities, #define is_twos_complement() ((-2 | -3) == -1) #define is_ones_complement() ((-1 & -2) == -3) #define is_sign_magnitude() ((-1 | -2) == -3) should distinguish them. >word_size(a), which returns the number of bits in a I suppose the simple solution #include #define word_size(a) (sizeof(a)*CHAR_BIT) is cheating. Hmm, if you want it to be *completely* portable, allowing for arbitrarily large values of CHAR_BIT (64 might actually be a reasonable option on a Cray!), I can't think of a way to do it offhand. I'd also like to be able to do `is_big_endian()' and `is_little_endian()', but I think these require run-time code. Karl W. Z. Heuer (karl@kelp.ima.isc.com or ima!kelp!karl), The Walking Lint