LB Booster
Programming >> Compatibility with LB4 >> GLOBAL in SUB isn't global http://lbb.conforums.com/index.cgi?board=compatibility&action=display&num=1430089625 GLOBAL in SUB isn't global
Post by Dacite on Apr 26th, 2015, 11:07pm
In LB4, you can declare a global variable in a SUB, but it doesn't work in LBB. It prints 0 in LBB, and 4294967295 in LB4. Something to be aware of... Code:
call Init
print m32
END
SUB Init
GLOBAL m32
m32 = 2^32 - 1
END SUB
- Dacite
Re: GLOBAL in SUB isn't global
Post by Richard Russell on Apr 27th, 2015, 06:23am
It would be something to be aware of, except that I cannot reproduce it! I copied your code, exactly as listed, into LBB v3.00, ran it, and it printed 4294967295. What do other people get?
Richard. Re: GLOBAL in SUB isn't global
Post by Mal on Apr 27th, 2015, 08:26am
I get the same as you, Richard.
Both gave the same answer.
If lines 5 and 6 are traded, different answers happen. LBB stays the same; LB gives 0.
Code:
call Init
print m32
END
SUB Init
m32 = 2^32 - 1
GLOBAL m32
END SUB
Malcolm
Re: GLOBAL in SUB isn't global
Post by Dacite on Apr 27th, 2015, 1:49pm
I'll be d**d - it works for me now too.
But it wasn't working - it was 0 in the later SUB when I was ANDing with it, and 0-ing out my array. The code worked right when I cut/pasted the declaration to the start of the code.
Note to self - In the future, restart LBB and see if the unexpected behavior goes away.
- Dacite
Re: GLOBAL in SUB isn't global
Post by tsh73 on Apr 27th, 2015, 2:32pm
>>it was 0 in the later SUB when I was ANDing with it
Might it be not integer? LBB rounds to integer before using in logical operations (so sometimes to 0), if I am right.