Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

DIM or LOCAL inside a Sub

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
PeterPiper

Bascom Member



Joined: 23 Mar 2006
Posts: 66

usa.gif
PostPosted: Thu Mar 06, 2008 10:31 pm    Post subject: DIM or LOCAL inside a Sub Reply with quote

What's the difference between dimensioning a variable within a sub routine, using DIM, as opposed to using LOCAL?
Back to top
View user's profile
AdrianJ

Bascom Expert



Joined: 16 Jan 2006
Posts: 2483
Location: Queensland

australia.gif
PostPosted: Fri Mar 07, 2008 1:00 am    Post subject: Reply with quote

Dim declares the variable as global, regardless of the fact that its in a Sub. You must use Local if you want it local to that sub.
_________________
Adrian Jansen
Computer language is a framework for creativity
Back to top
View user's profile Visit poster's website
Luciano

Bascom Member



Joined: 29 Nov 2004
Posts: 3149
Location: Italy

blank.gif
PostPosted: Fri Mar 07, 2008 6:11 pm    Post subject: Reply with quote

Hi,

See Bascom AVR help file DIM and LOCAL.

SCOPE

The scope for DIM is global. So no matter where you use the DIM statements, the variable will
end up as a global visible variable that is visible in all modules, procedures and functions.

When you need a LOCAL variable that is local to the procedure or function, you can use LOCAL.

* * *

A LOCAL variable is a temporary variable that is stored on the frame.
When the SUB or FUNCTION is terminated, the memory will be released back to the frame.
Since LOCAL variables are stored on the frame, it takes more code to dynamic generate and clean up these variables.
Local BIT variables are not possible because they are GLOBAL to the system.


* * *

See this thread about stack: (The Frame).
http://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=3220

Best regards,

Luciano
Back to top
View user's profile
PeterPiper

Bascom Member



Joined: 23 Mar 2006
Posts: 66

usa.gif
PostPosted: Sun Mar 09, 2008 5:13 am    Post subject: Reply with quote

Thanks. The "manual" isn't too clear about dimensioning using DIM inside or outside of a sub routine.
Back to top
View user's profile
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum