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 Marcus Sundman on Mon 19th Apr 2004 21:34 UTC

> it's safer to use a null pointer as an empty array

Huh? I have no idea what you're babbling about, but a null pointer and an empty string are two completely different things, just as a null pointer and the string "hello" are different. The fact that the length of the string "" is 0 doesn't mean that it suddenly isn't a string at all!

Let's say I have a method for setting the password, setPassword(string newPassWord). Then consider this scenario:
| string newpw;
| switch (pwmode) {
| case 0: newpw=getNewPassWord(); break;
| case 1: newpw=readPassWord(stdin); break;
| }
| setPassword(newpw);
Now someone adds a new pwmode, 2, and so setPassword(null) will be called, but the setPassword method thinks this is an empty password (which are used for auto-logins) instead of throwing an InvalidNullArgumentException or similar.
This wasn't a very good example, but I hope you get the point. The point was that there is a very clear distinction between en empty string and no string at all.