>
> Could not the Z (our Z!) implementation of C used something like
> 7FFFF000 for NULL and thereby trapped the dereferencing of NULL? (And
> yes, some provision would have had to be made for the PSA.)
>
> Charles
It _could_ - but consider this example:
struct my_struct {
int foo;
int *foop;
int bar;
int *barp;
} m = { 0 } ;
This complicates things - does "m.foop" get 0x00 bytes or something else?
The compiler would be obliged to put a 0 into the members 'foo'/'bar', and
NULL-pointer values into the members 'foop' and 'barp'. Instead of a simple
set-all-the-bytes-to-zero (which could become a simple MVC...)
Also, what would:
memset(&m, 0, sizeof(m));
do? (It would be zero-bytes in the structure, and 'foop' would
then no-longer be NULL.) And, then what does:
if(m.foop == 0) {
mean... the compiler would be obliged to compar 'foop' with the NULL-pointer
value, and instead it would be zero... which is a little surprising.
That's a very common idiom, and, back to the POLA (Principle of Least
Astonishment) programmers would (naively) expect that to set the pointers
to the NULL pointer. But, memset() does not do that... (it has no way to
know.)
Technically, that's not "right" - but it's just what is done.
So, I think it's best for NULL to actually be the value zero.
Note that even when we choose zero for the NULL pointer, there _is_ a
problem on the mainframe caused by the VL-bit. If a C function's last
incoming parameter is a pointer variable, and it is invoked by something
sets the VL-bit in the last parameter, then the compiler is obliged
to "clean" the VL-bit so that comparisons with 0 generate simple code.
You don't want this "cleaning" at every such comparison (and in the event
of variable arguments you don't know at compile-time which is "last".)
Our compiler says that we (mostly) assume pointers, even pointers from
the last parameter, are "clean" (unless you tell us otherwise, and there
are mechanisms for that)... so there isn't a bunch of mostly non-needed
"cleaning" going on in the generated code.
That is, even when we choose zero for the NULL pointer variable, things
on the mainframe get somewhat complicated.
- Dave R. -
--
[email protected] Work: (919) 676-0847
Get your mainframe programming tools at http://www.dignus.com