Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Given all the confusion surrounding null pointers, wouldn it be easier simply to require them to be represented internally by zeroes?

0
Posted

Given all the confusion surrounding null pointers, wouldn it be easier simply to require them to be represented internally by zeroes?

0

If for no other reason, doing so would be ill-advised because it would unnecessarily constrain implementations which would otherwise naturally represent null pointers by special, nonzero bit patterns, particularly when those values would trigger automatic hardware traps for invalid accesses. Besides, what would this requirement really accomplish? Proper understanding of null pointers does not require knowledge of the internal representation, whether zero or nonzero. Assuming that null pointers are internally zero does not make any code easier to write (except for a certain ill-advised usage of calloc; see question 3.9). Known-zero internal pointers would not obviate casts in function calls, because the _size_ of the pointer might still be different from that of an int. (If “nil” were used to request null pointers rather than “0,” as mentioned in question 1.11, the urge to assume an internal zero representation would not even arise.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123