AutoHotkey Community

It is currently May 27th, 2012, 3:28 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: June 12th, 2010, 9:24 am 
Offline

Joined: September 23rd, 2009, 6:33 pm
Posts: 19
If I declare one of variables in a function local, all other variables in the function become global. Is is confusing and could lead to errors.

Code:
my_func()
{
   local my_local1 := "local value 1" ; if "local" is present here, my_local2 becomes global. If "local" is removed before my_local1, then my_local2 is local
   my_local2 := "local value 2"
}

my_func()

; The following MsgBox can unexpectedly see the value of my_local2; which is in fact global
MsgBox my_local1="%my_local1%"; my_local2="%my_local2%"


[/code]

[Moved from Bug Reports forum. ~jaco0646]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 12th, 2010, 9:29 am 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
This behavior is intentional.

AHK Help File wrote:
Assume-global mode: If a function needs to access or create a large number of global variables, it can be defined to assume that all its variables are global (except its parameters) by making its first line either the word "global" or the declaration of a local variable.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 13 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group