Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Differences where variable dimensioned?

 
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 Unsupported versions
View previous topic :: View next topic  
Author Message
KenHorse

Bascom Member



Joined: 16 Jul 2004
Posts: 519

blank.gif
PostPosted: Sat Aug 07, 2021 6:25 pm    Post subject: Differences where variable dimensioned? Reply with quote

Is there any practical difference between declaring a variable this way:

Code:
Sub Whatever
Dim Array(10) as Byte
    <code of sub>
End Sub


versus this:


Code:


Dim Array(10) as Byte

Sub Whatever
   <code of sub>
End Sub
[/code]

(BASCOM-AVR version : 2.0.8.3 , Latest : 2.0.8.4 )
Back to top
View user's profile
Evert :-)

Bascom Expert



Joined: 18 Feb 2005
Posts: 2132

netherlands.gif
PostPosted: Sat Aug 07, 2021 7:31 pm    Post subject: Reply with quote

Form the help file:

Quote:

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.
Since LOCAL variables are stored on the frame, it takes more code to dynamic generate and clean up these variables. This because all functions and subs are fully re-entrant. (re-entrant means they can call themselves recursively)


So, no there's no difference.
Except that in the second case it's clear that the variable belongs(needed by) to the sub.

_________________
www.evertdekker.com Bascom code vault
Back to top
View user's profile Visit poster's website
KenHorse

Bascom Member



Joined: 16 Jul 2004
Posts: 519

blank.gif
PostPosted: Sat Aug 07, 2021 8:09 pm    Post subject: Reply with quote

And where those variables are actually stores within RAM, yes?
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 Unsupported versions 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