|
|
|
|
|
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. |
|
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.