No way to tell if an integer is null

BlitzMax Forums/BlitzMax Programming/No way to tell if an integer is null

plash(Posted 2008) [#1]
Can this be updated for BlitzMax 1.30??? (pretty please)
SuperStrict

Local integer:Int = Null

If integer = Null Print "Variable, 'integer', is null!"
If integer = 0 Print "Variable, 'integer', is zero!"



ziggy(Posted 2008) [#2]
A integer can never be null becouse it is not a reference to a instance of a class. converting base types to objects would have a terrible performance hit and would force every single variable to deal with the GC.IMHO I don't think it is a good idea...


ImaginaryHuman(Posted 2008) [#3]
Also if you think about it in order to represent an integer as null you'd have to have SOME kind of `value` that you store in the integer that represents null. What is that value going to be, in order to not create problems or incompatibilities? It might as well be 0.

You'll also find that for example FunctionPointer=Null actually sets a function pointer to point to a function called Null.


Gabriel(Posted 2008) [#4]
You won't get it changed, too many people are already using it as it is, and a change would break too much code. If you want different behaviour, can't you just do something like

Const MyNull:Int = -2147483648



Czar Flavius(Posted 2008) [#5]
To answer the topic title more directly, you cannot check if an integer is null, because an integer is never null :)


(The worst you can get in C/etc is 'undefined', not the same thing)


Floyd(Posted 2008) [#6]
According to the Language Reference the default value of every data type is Null.

Thus a null string is empty, a null integer is zero, etc.


plash(Posted 2008) [#7]
You won't get it changed, too many people are already using it as it is, and a change would break too much code. If you want different behaviour, can't you just do something like
Ya that is what I'm doing now (but using a smaller number, -65535; no I'm not using a short).

Overall I was under the impression that an int already was an *object* (internally).

So why are Null strings actually ""?? (as there is a string type, no?)
Local str:String = Null

If str = Null Print "Variable, 'str', is null!"
If str = "" Print "Variable, 'str', is ~q~q!"

str = ""

If str = Null Print "Variable, 'str', is null!"



Koriolis(Posted 2008) [#8]
This is a special case for strings. Empty strings are treated the same as null references by the comparison operators.


Dreamora(Posted 2008) [#9]
One might tell many bad things about the BM documentation. But the default value assignement for the different types has been in since day one!

1. String: ""
2. Numerics: 0
3. Objects other than String: NULL

Unlike C++ and other languages, in BM NULL is NOT the same as 0
NULL is of type Object, 0 is of type Int -> incomparable


Grey Alien(Posted 2008) [#10]
Agree with Dreamora although you can also test for String=null and it's the same as string=""

Ints/Floats etc are not objects, they are the same as in C++


Czar Flavius(Posted 2008) [#11]
According to the Language Reference the default value of every data type is Null.
Well I guess in theory the documentation wins! But in practice I wouldn't consider 0 to be null, but this is all an academic discussion of documentation by this stage :)