Hacker News new | ask | show | jobs
by mikeash 4913 days ago
It comes down to this:

Zero is not nothing. Sometimes it means nothing, which is not the same thing.

C pointer types are always option types. They can hold "nothing" or a pointer. Code that deals with pointers always has to deal with this option nature of the types, whether it wants the feature or not.

C primitive types are never option types. They can never hold "nothing". Some of them can hold a value that is sometimes used to represent "nothing", but again, that is not the same thing. Code that deals with primitive types and wants to be able to represent "nothing" either has to keep a separate flag or borrow a value from the primitive type's range to indicate "nothing" without any language support for that.

In short: I object to C mixing option types with pointer types. Life would be simpler if they were separate. NULL (nil etc.) is how C indicates "none" for pointers. C has no built-in indicator for "none" for primitives.

1 comments

"Zero is not nothing."

Yes. In a computer, there is nothing that is nothing. You always have something that signifies nothing.

C pointers also do not hold "nothing". What you refer to as "nothing" is the address 0, which is a special value that the language makes certain guarantees about that you interpret as being "nothing" because of these guarantees.

> C pointers also do not hold "nothing". What you refer to as "nothing" is the address 0, which is a special value that the language makes certain guarantees about that you interpret as being "nothing" because of these guarantees.

Of course. The point is that pointers have that "special value", while primitives do not. The integer value 0 is not the same thing.

You're both right. Zero does mean nothing. Also, zero is not a special value for integers like it is for pointers. Enough of this self-righteous debate.
Dude, that is exactly what I was saying...
I never claimed it was. Sheesh.