Path: utzoo!attcan!uunet!zaphod.mps.ohio-state.edu!ncar!noao!arizona!dave From: dave@cs.arizona.edu (Dave P. Schaumann) Newsgroups: comp.lang.c Subject: Re: Style guides and portability Message-ID: <653@caslon.cs.arizona.edu> Date: 13 Jan 91 06:04:32 GMT References: <1163@tredysvr.Tredydev.Unisys.COM> <14824@smoke.brl.mil> Distribution: comp Organization: U of Arizona CS Dept, Tucson Lines: 41 In article bevan@cs.man.ac.uk (Stephen J Bevan) writes: || No, any C compiler worth using (and certainly any that conforms to the || standard) will provide at least 16 bits for an int, at least 32 bits || for a long, and at least 8 bits for a char. While there are uses for || user-defined primitive data types (for example, I use "bool" and || (generic object) "pointer" types), I don't think that int16, int32, etc. || are justifiable. | |What about the cases where it is a requirement that a particular int |MUST be able to hold 32 bit numbers. If you transfer this to a 16 bit |int system, your software is going to die horribly. | |The only way I know around this is to define types like int32 and a |lot of macros/functions that go along with them. For example, |int32plus, int32divide, ... etc. | |Does anybody have a better solution ? How about using something like: #include [...] if( sizeof(int) * CHAR_BITS / sizeof(char) < 32 ) { /* have 32 bit ints? */ fputs( "Must have at least 32 bit ints!\n", stderr ) ; exit(1) ; } While this won't make the program work, it will certainly indicate to the people porting the code that they need to use a more capacious integer type. Also, I believe that the ANSI standard *requires* that longs be at least 32 bits. Of course, you may run across a compiler that is less than 100% compliant... |Stephen J. Bevan bevan@cs.man.ac.uk Dave Schaumann | We've all got a mission in life, though we get into ruts; dave@cs.arizona.edu | some are the cogs on the wheels, others just plain nuts. -Daffy Duck.