Hi mikroE,
I can not acces to local variables in subP and subF.
Either in simulation or debug i can not access to the local variable "prova".
Am i doing somethig wrong?
Thank you,
Alex
Simple test program:
program MyProject
' Declarations section
Sub procedure test1()
dim prova as byte
prova = prova +1
end sub
main:
test1()
nop
end.
uBASIC Local variabiles strange behave
-
- Posts: 101
- Joined: 04 Nov 2016 13:09
- jovana.medakovic
- mikroElektronika team
- Posts: 986
- Joined: 18 Dec 2018 10:36
Re: uBASIC Local variabiles strange behave
Hello,
In the declaration of the variable, add the word volatile about which you can read in our help file from the compiler.
Kind regards,
Jovana
In the declaration of the variable, add the word volatile about which you can read in our help file from the compiler.
Code: Select all
dim prova as byte volatile
Jovana
-
- Posts: 101
- Joined: 04 Nov 2016 13:09
Re: uBASIC Local variabiles strange behave
Hi Jovana,
Thank you very much for your answer. That clarify something.
But i still struggle to understand something...
I'v read many(50) of your uB examples and nobody have never declared as "volatile" a variable inside a procedure or a function.
It seems that who wrote those examples was expecting a standard local variables bheave...
If you try the follow simple example you will see that the procedure test1() is working fine without the "volatile" declaration,while the test2() it is working as in my previous post.
It seems that who wrote those examples was expecting a standard beheave from local variables...
If you debug the follow code in assembly, then you see that test1() has the right assembly program, while the routine test2() it's empty!
Let me know your opinion, and if this things can be fixed.
Thank you very much,
Alex
dim pippo as byte
Sub procedure test1()
dim temp as byte
inc(temp)
pippo = temp
end sub
Sub procedure test2()
dim temp as byte
inc(temp)
end sub
while true
test1()
test2()
wend
Thank you very much for your answer. That clarify something.
But i still struggle to understand something...
I'v read many(50) of your uB examples and nobody have never declared as "volatile" a variable inside a procedure or a function.
It seems that who wrote those examples was expecting a standard local variables bheave...
If you try the follow simple example you will see that the procedure test1() is working fine without the "volatile" declaration,while the test2() it is working as in my previous post.
It seems that who wrote those examples was expecting a standard beheave from local variables...
If you debug the follow code in assembly, then you see that test1() has the right assembly program, while the routine test2() it's empty!
Let me know your opinion, and if this things can be fixed.
Thank you very much,
Alex
dim pippo as byte
Sub procedure test1()
dim temp as byte
inc(temp)
pippo = temp
end sub
Sub procedure test2()
dim temp as byte
inc(temp)
end sub
while true
test1()
test2()
wend
Re: uBASIC Local variabiles strange behave
Guessing a bit, but if mikroBasic is similar to mikroC, then the compiler will notice that test2() does absolutely nothing in the real world, and will optimise out the code.
Not sure, but if you turn on warnings and hints in compiler output window, you may, or may not get some indication of "temp" local variable removed.
Could be wrong (but I reckon I am right )
Not sure, but if you turn on warnings and hints in compiler output window, you may, or may not get some indication of "temp" local variable removed.
Could be wrong (but I reckon I am right )
Start every day with a smile...... (get it over with)
-
- Posts: 101
- Joined: 04 Nov 2016 13:09
Re: uBASIC Local variabiles strange behave
Hi Hexreader,
Yes, you're right!
11 1520 variable 'temp' might not have been initialized MyProject.mbas
25 1011 Hint: Variable "temp" has been eliminated by optimizer MyProject.mbas
I wonder if the optimizer can be switched off on some specific routines...
Do you know where i can find informations on the uB optimiser?
Thank you very much!
Alex
Yes, you're right!
11 1520 variable 'temp' might not have been initialized MyProject.mbas
25 1011 Hint: Variable "temp" has been eliminated by optimizer MyProject.mbas
I wonder if the optimizer can be switched off on some specific routines...
Do you know where i can find informations on the uB optimiser?
Thank you very much!
Alex
- jovana.medakovic
- mikroElektronika team
- Posts: 986
- Joined: 18 Dec 2018 10:36
Re: uBASIC Local variabiles strange behave
Hi,
When you run the compiler, go to Tools -> Options -> Output Settings and there you can set Optimization level.
Kind regards,
Jovana
When you run the compiler, go to Tools -> Options -> Output Settings and there you can set Optimization level.
Kind regards,
Jovana