Pass a variable using the function without having global var

Post your requests and ideas on the future development of mikroBasic PRO for PIC.
Post Reply
Author
Message
leo73
Posts: 252
Joined: 09 Jan 2014 15:45

Pass a variable using the function without having global var

#1 Post by leo73 » 05 Oct 2014 13:20

If i have this program:
__________________________________________________________________________-
program ProvaPassaggioVariabilr16F88

dim y as byte '<--- I don't want use this global Variable

' Declarations section
sub function funzione(dim x as byte) as byte ' DefineCircle function returns a byte value
result = x
end sub

main:
'dim y as byte <---- i want use the variable here as local(what about save memory pic) but compiler see me an error

' Main program
y = funzione(5)
nop
end.
__________________________________________________________________________

why? is required declare the variable as Global, and i can't use it as local where i need? it's ridicolous!!! :evil:
thank you.
Leonardo

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

Re: Pass a variable using the function without having global

#2 Post by janni » 05 Oct 2014 16:08

leo73 wrote:why? is required declare the variable as Global, and i can't use it as local where i need? it's ridicolous!!! :evil:
It isn't required to declare y as global. Optimizer probably removed this variable (and assignment) when declared as local because it wasn't used later on. For debugging, when you want optimizer to refrain from optimizing out a variable, use the volatile specifier, like

Code: Select all

main:
 dim y as byte volatile

Post Reply

Return to “mikroBasic PRO for PIC Wish List”