Null = 0

BlitzMax Forums/BlitzMax Beginners Area/Null = 0

Kistjes(Posted 2008) [#1]
Hi all,

Is there a way to notice the difference between the value 0 and Null for Int types?
I thought that Null was something like "Not declared" but it seems to be equal to 0.

In the following two versions of a simple test function, BlitzMax doesn't notice the difference between 0 or Null when I call it with
Test(5)
or Test(5,0)

Function Test(a%, b% = Null)
	If Not b Then b = 10
	Return (a + b)
End Function

or
Function Test(a%, b% = Null)
	If b = Null Then b = 10
	Return (a + b)
End Function



grable(Posted 2008) [#2]
Is there a way to notice the difference between the value 0 and Null for Int types?

No, Null is an Object specific identifier and will always be converted to the default "zero" state of any variable type.
Use a magic value instead, like -1 or some other value that your input doesnt use.


Kistjes(Posted 2008) [#3]
Use a magic value instead, like -1 or some other value that your input doesnt use.

That's what I'm doing now but sometimes that's a bit tricky.

Thanks anyway!


Czar Flavius(Posted 2008) [#4]
Use -2147483648 as your magic number.


Digital Anime(Posted 2008) [#5]
If you want the the following to work

Function Test(a%, b% = Null)
	If b = Null Then b = 10
	Return (a + b)
End Function


you could do it this way if b should be 10 if nothing is filled in

Function Test(a%, b% = 10)
	Return (a + b)
End Function