Debug behaviour with global array init

Archives Forums/BlitzMax Bug Reports/Debug behaviour with global array init

BlitzSupport(Posted 2012) [#1]
Not sure if this is a bug, just noting as I ran into it.

If you run this in Debug mode, it errors out with a complaint about indexing beyond the end of the array, which I assume is something to do with the global array dtable not having been initialised before it's accessed.

However, the weird thing is that it runs and works perfectly in Release mode!

' From code by Nilium...

InitBase64

Const etable$ = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
Global dtable@[256]

Function InitBase64 ()
	For Local __di:Int = 0 To etable.Length-1
	    dtable[etable[__di]] = __di
		Print dtable[etable[__di]]
	Next
End Function


No big deal, just shifted the Global to the top, but wondered if Debug mode should be flagging it since it's clearly initialised in Release mode.


Bobysait(Posted 2012) [#2]
That's not an error, it's just due to the release mode that process declarations while "exporting" to exe, so the global array is created before all function calls as it's in the "main"

It's probably an effect of the smart declaration of blitzmax, that in opposite to C/C++ does not ask us to declare a function before to call it
for eg: in C, you would not have call your function without running an error, as the function does not exist at the moment of the call (that's the most important reason we use headers)

In debug mode, it might have a deal with the ability to run a kind of "line by line analysis"

Then, As you declared the global array after initializing the Base64, so the array is Null at the moment of the function call


ps : and for sure, if there were a bug here, it would probably be in the release mode that allow this (IMHO, it should run an exception, 'cause of the messy declaration)

Last edited 2012