Here are three examples of computers which have used something other than all-bits-0 for null pointers:
- the Prime 50 series
- the CDC Cyber 180 Series
- some Honeywell-Bull mainframes
I can't say whether there are or were ever ANSI C compilers for these machines, however.
For further details, see question 5.17 in the C FAQ list.
Addendum: I suspect there are really two questions here:
- Have there actually ever been machines with nonzero null pointers?
- Is it safe in 2022 to write
memset(&ms, 0, sizeof(ms))
, as in the example in this question, and expect pointer values like ms.somePointer
to come out as proper null pointers?
The answer to question 1 is undeniably "yes". (The question becomes less clear, though, if we change "Have there actually ever been" to "Are there".)
The answer to question 2 is, I think, still a matter of opinion. My own answer would be "Yes, it's safe, although I wouldn't do it, unless I was in a big hurry." That is, after memsetting all my newly-allocated C structs to 0, I still like to explicitly set any pointer fields to NULL
.
But I think this is the sort of thing that every project needs to decide for itself, as part of its overall style/best practices guide. For certain issues like this one, it's still unfortunately somewhat of a judgement call whether to say "Thou shalt write 100% strictly conforming C code always", versus "We accept this practice, even though it may not be 100% strictly conforming, because we believe it should work everywhere, on any reasonable platform we care about."
Many times, saying "I believe this practice, though not guaranteed to work, should work on any reasonable platform" is quite perilous. But sometimes, it's perfectly reasonable. As I said, it can be a judgement call.