Author |
Topic: GLOBAL in SUB isn't global (Read 424 times) |
|
Dacite
New Member
member is offline
Posts: 6
|
|
GLOBAL in SUB isn't global
« Thread started 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
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: GLOBAL in SUB isn't global
« Reply #1 on: Apr 27th, 2015, 06:23am » |
|
on Apr 26th, 2015, 11:07pm, Dacite wrote:Something to be aware of... |
|
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.
|
|
Logged
|
|
|
|
Mal
New Member
member is offline
Gender:
Posts: 3
|
|
Re: GLOBAL in SUB isn't global
« Reply #2 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
|
|
Logged
|
|
|
|
Dacite
New Member
member is offline
Posts: 6
|
|
Re: GLOBAL in SUB isn't global
« Reply #3 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
|
|
Logged
|
|
|
|
tsh73
Full Member
member is offline
Gender:
Posts: 210
|
|
Re: GLOBAL in SUB isn't global
« Reply #4 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.
|
|
Logged
|
|
|
|
|