Null = 0
BlitzMax Forums/BlitzMax Beginners Area/Null = 0
| ||
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 |
| ||
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. |
| ||
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! |
| ||
Use -2147483648 as your magic number. |
| ||
If you want the the following to workFunction 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 |