#if sizeof(int)

William E. Davidsen Jr davidsen at steinmetz.ge.com
Fri Apr 15 01:47:50 AEST 1988


In article <1988Apr12.135141.3122 at sq.uucp> msb at 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 at ge-crd.arpa)
  {uunet | philabs | seismo}!steinmetz!crdos1!davidsen
"Stupidity, like virtue, is its own reward" -me



More information about the Comp.lang.c mailing list