Variable Declaration

BlitzMax Forums/BlitzMax Programming/Variable Declaration

(tu) ENAY(Posted 2005) [#1]
Just wondering, about variable declaration in Blitzmax.

For example, C++ style if you have 2 classes where one refers to the other you can include the header file within so that the compiler knows these parameters are declared elsewhere.

In Blitzmax if I create something I need to create the parented variable before the one after it.

Is there anyway to declare variables at the beginning so strict declaration order isn't necessary.

Heh. Hope that made sense. :)

Crap example:-

main.bmx
include "parp.bmx"
include "turnip.bmx"


parp.bmx
global parp = turnip ; turnip does not exist because it hasn't been declared till later


turnip.bmx
global turnip = 0



Robert(Posted 2005) [#2]
Initialise turnip at a later point in the code. Generally speaking, it isn't a good idea to rely on the order in which global variables are initialised. I managed to create a very troublesome bug in a C++ project by doing this.


boomboommax(Posted 2005) [#3]
.


(tu) ENAY(Posted 2005) [#4]
Yes, but this is my point, I don't want to rely on the order. For example what if Turnip and Parp reference each other? There will be an error which ever order they're initialised in.

Or is my only choice to have a whole list of variable declaration at the start before any includes?


Dreamora(Posted 2005) [#5]
If they reference each other, you will have to use include or you get circle import error and compile refuse, thats it :-)

And in best you don't default initialize anything but initialize it on first usage *some kind of start or init function*

This way you have a granted moment from which on it is initialized.