Dim and include mixup

Archives Forums/Blitz3D Bug Reports/Dim and include mixup

Fernhout(Posted 2010) [#1]
This one is a odd one.

i made a program and used ready made code. e.g:
Include "buttons.bb"
Include "MapShift.bb"

Dim ButtenReturn(25)
Dim ButtonSelected(25)
Dim WorldMap(100,100)
ect.

Nothing wrong here. But when i compile the compiler says:
Expection ")"
and opens the include file Mapshift.bb pointing out the first line where WorldMap(x,y) occurse.

The include file is a compleet Function so it wil execute later.
But on the same way there is no warning on the first two dim statments.

I can understand why the warning is comming during precompiling the arrar can not set. But the strange thing i get is when i replace only the Worldmap arrar above the include and the rest stay the same. e.g.:
Dim WorldMap(100,100)
Include "buttons.bb"
Include "MapShift.bb"

Dim ButtenReturn(25)
Dim ButtonSelected(25)

ect.

Then the compiling is working and the program is working to. Even if i fill out the buttenReturn array complete and read them out there is nothing going wrong. I was expecting during the program run in debug mode to get an error Array out of bound. But nothing of that.

My question here is:
Why can i compile the second option and not getting any problems. If the precompiling is working with the one array why not with the two array.

Can anybody explain me what is wrong here.


Dreamora(Posted 2010) [#2]
The problem you get there is that the bb is preprocessed on include. When it does so, it checks if all the used stuff within the bb is defined already.

As the source is checked from top to bottom, only the things declared before the include call are "defined" for the included file at that point. The rest of the "main source file" has not been processed yet, so the declarations after the include don't exist.


This is a bit inconsistent to the behavior of the rest of blitz as the "order" only is of importance in this case, yet its an important and easy to remember exception