Linked by Owen Anderson on Mon 19th Apr 2004 05:43 UTC
General Development For years the development scene has been dominated by the C family of languages, primarily C itself and its immediate successor C++. Recent years have given rise to other C-descendents, however, such as Sun's Java and Microsoft's C#.
Permalink for comment
To read all comments associated with this story, please click here.
RE: Null Pointers
by J.F. on Tue 20th Apr 2004 18:16 UTC

I did reread it, several times. I've probably read it ten times already but I dimply don't understand what you're trying to get across. To me it seems like you're discussing how to optimize zero length arrays, but that is completely irrelevant. I couldn't care less about the low-level implementation of arrays. What I do want is that empty strings be different from null. Am I not making myself clear enough?
| a=""; b=null;
| if (a==b) {
| // this MUST NOT happen
| }
Do you agree?


Not necessarily. What is wrong with having the two be equivalent? As I said, since you are already loading the register to use the pointer and may also do arithmetic on it, it takes no extra time to check if it's null and to treat it separately. This also has the added advantage of dealing with null pointers passed by bad code.

Say that a is not equal to b from your example above. Now someone passes in a or b set to null. This case must be handled using separate code or risk a dangling reference to unmapped memory. PC OSes usually use the MMU to pick up such cases via page faults. This is a necessary evil to catch sloppy programming.

It's not an optimization so much as a method to also catch dangling pointers. Otherwise, you might need code like this:

if (!a || !b) {
// one string null!
}