6 ms·
Also, null might be the empty string, but when is it ever zero? Edit: this is a serious question.
by perl4ever 7y ago
Also, null might be the empty string, but when is it ever zero?
Edit: this is a serious question.
- mikestew 7y agoYou can look at headers: #define NULL 0 //C++ #define NULL ((void*)0) //C I think later versions of C++ do something...different, but I’m not up to date enough to know without looking it up.
- perl4ever 7y agoOk, I wasn't thinking of C, but even so, isn't NULL a pointer value, not an integer? If you're treating a null pointer as an integer zero, something's gone very wrong. Also I think I vaguely remember from discussions about the standards, that a NULL pointer is not guaranteed to be numerically equal to zero in a standards compliant compiler. But yeah, I was thinking of database NULLs.
- boring_twenties 7y agoC++03 and earlier stipulate that literal 0 is always the null pointer, whether it really is on any given hardware or not. C++11 and later deprecate this and introduce a new keyword `nullptr`. edit: Also, null is not an empty string. The null character that terminates a string is unrelated to null pointers.
- mikestew 7y agoMan, this is one of those discussions I’d like to drag out for a little bit, but unfortunately not in a position to do so. I will leave you with the idea that null can indeed be a value, as in a null-terminated string. Go look at that guy in memory.
- perl4ever 7y agoIf you're going to split hairs, I'm going to say a NUL character is obviously not the same concept as a NULL in general, nor is it a number that you'd use for a coordinate.
- boring_twenties 7y agoThe definition of NULL is technically machine-dependent in C. It happens to be 0 on (almost?) every machine, but that's not guaranteed. In C++ it's guaranteed to be 0.
- simcop2387 7y agoThe times where it wasn't zero are interesting, https://stackoverflow.com/questions/2597142/when-was-the-null-macro-not-0 https://stackoverflow.com/questions/2597142/when-was-the-nul...
- boring_twenties 7y ago"May you live in interesting times!"
- cdumler 7y agoA language that truly supports null has monadic types, meaning that typed value (scalar, string, object, etc) or something else is specifically tracked (null, undefined, etc). Languages that do not natively support that often have developers that cheat, where they assign some particular value to represent null. Commonly, this is 0 or -1 in numbers and an empty or literal "null" in strings. This works fine unless these values appear actually as legitimate values.
- perl4ever 7y agoLately, I program in a language that has distinct concepts of Null and Empty and Nothing and the empty string ("") and arrays that are not Empty but contain zero elements. And of course NUL characters. This is obviously at least five times as good as just having one option for null.
- speedplane 7y ago> arrays that are not Empty but contain zero elements What is an array that is not empty but contains zero elements?
- saagarjha 7y agoSounds like a trick question. How about the array of the largest number?
- anonymfus 7y agoIIRC in Visual Basic these are arrays with lower bound bigger than upper bound.
- perl4ever 7y ago...but sometimes you can observe this and sometimes you can't.
- perl4ever 7y agoWell, Empty is a special value in VBA. And I forgot to mention, there are two kinds of "empty" arrays that are not Empty. So it's six times as good as a normal language. Here's an example: ' x can be anything, including an array, but ' defaults to the value Empty. Dim x ' y is an array of values that can be anything, ' which defaults to an empty array. Dim y() ' Initialize x as an empty array x = Array() ' The following two statements print 0 and -1. Debug.Print LBound(x) Debug.Print UBound(x) ' The following two statements error with ' "Subscript out of range" even though y ' is also a kind of empty array. Debug.Print LBound(y) Debug.Print UBound(y)
- endorphone 7y agoIt's a fair point. Null is the absence of a value. When used in a programming context it is either a pointer (which is not an integer or a float -- it's the pointer to the absence of an integer or a float. It is not equivalent to 0 or 0.0 or ""), a magic number (specifically for chars), or a special structure with a flag. This more correctly would be "Default=0 Island". A database that doesn't have a nullable field would be the one where you'd have 0.0 as the defaults.
- sverhagen 7y ago>It's a fair point. Pun.
- gwbas1c 7y agoWhen it's a pointer. Remember, a pointer contains the actual address in RAM, or 0 when the pointer is null.
- saagarjha 7y agoUsually, but not always.