NULL question not in FAQ
Checkpoint Technologies
ckp at grebyn.com
Thu Mar 28 05:41:01 AEST 1991
In article <1991Mar26.235643.4498 at ux1.cso.uiuc.edu> phil at ux1.cso.uiuc.edu (Phil Howard KA9WGN) writes:
>Given that the compiler is supposed to translate the constant "0" to the
>appropriate value for a NULL pointer on the machine type, how does one
>get a pointer value whose representation happens to be all zeroes, but
>is a non-NULL pointer?
void some_func(void) {
int **ip;
ip = (int **) calloc(sizeof(int *), 1);
...
And now, *ip is a pointer whose representaiton is all-bits-zero, which
of course is not guaranteed to be NULL, but *probably is on your
implementation. Most architectures are not capable of distinguishing
between a pointer representation of all-bits-zero, and a null pointer.
But you as a programmer should make this distinction.
And, if I might restate the rest, for brevity...
I am comfortable with the idea that 0 may be transformed into the null
pointer value. However, the FAQ says that the *compiler* translates
the integer 0 *constant* into the null pointer. It says nothing about
transforming, at run time, integer zero values which may be in an object.
Therefore, the following is not guaranteed to give me a null pointer:
int i = 0;
char *p = (char *)i;
So is it correct to interpret this code as unportable?
--
First comes the logo: C H E C K P O I N T T E C H N O L O G I E S / /
ckp at grebyn.com \\ / /
Then, the disclaimer: All expressed opinions are, indeed, opinions. \ / o
Now for the witty part: I'm pink, therefore, I'm spam! \/
More information about the Comp.lang.c
mailing list