How do a write portable programs?

Karl Heuer karl at haddock.ima.isc.com
Sat Sep 10 05:45:15 AEST 1988


In article <2515 at ingr.UUCP> jones at ingr.UUCP (Mark Jones) writes:
>In article <1056 at nmtsun.nmt.edu>, warner at hydrovax.nmt.edu (M. Warner Losh) writes:
>> write portable 'C' code.  Things like don't use 0, use NULL, but be
>> sure to always cast it.
>
>Instead of using NULL, use ZERO, and don't worry about casting it.  [Because
>K&R guarantees that `0' denotes a null pointer constant.]

`NULL' is more meaningful than `0', in a context where it isn't otherwise
obvious that you're dealing with a pointer.  But since we're talking about
portability issues, I'll grant that they're equally good ways to represent a
null pointer constant.  But the cast is required in one situation: a function
argument not covered by a prototype.

>#if sizeof(int) == 4

You can't use sizeof() in an #if expression.  If you have ANSI C's <limits.h>,
you can write as `#if INT_MAX >= 0x7fffffff' to get the effect you want.

Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint



More information about the Comp.lang.c mailing list