| View previous topic :: View next topic |
| Author |
Message |
Hardeep
Joined: 02 Jul 2006 Posts: 87
|
Posted: Thu Jul 19, 2007 1:04 pm Post subject: Bug in parsing Local declaration |
|
|
AHK Version : 1.0.47.01
When a variable is initialized to a numeric value inside a multiple Local declaration, the spaces/tabs added to the right of the numeric value but before a comma, get appended to the variable.
| Code: | Myfunc()
{ Local x=1 , y=2, z=3
MsgBox,% x y z ;Shows "1 23"
}
Myfunc()
| This only happens when setting variables to numeric values |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6551 Location: Pacific Northwest, US
|
Posted: Thu Jul 19, 2007 3:06 pm Post subject: |
|
|
variables are local by default, why are you declaring them so? does it work if you leave out the local? (I suppose that forces you to use multiple lines then?) _________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Thu Jul 19, 2007 3:11 pm Post subject: |
|
|
This has been fixed in today's v1.0.47.02: "Fixed declaration initializers not to retain whitespace at the end of literal numbers. Also, they now allow spaces between a closing quote and the next comma."
Thanks for reporting it. |
|
| Back to top |
|
 |
Helpy Guest
|
Posted: Thu Jul 19, 2007 3:35 pm Post subject: |
|
|
| engunneer wrote: | | variables are local by default, why are you declaring them so? | Because it is a good programming habit to declare local variables, and it allows global variables to be visible, which is a more familiar paradigm for lot of programmers... |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6551 Location: Pacific Northwest, US
|
Posted: Thu Jul 19, 2007 3:39 pm Post subject: |
|
|
an even better answer is that it allows you to keep some variables local when the variables in the function are changed to global-by-default. - in fact, using Local in this way sets all the others to global by default.
| Quote: |
If a function needs to reference 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. For example:
| Code: |
SetDefaults()
{
global ; This word can be omitted if the first line of this function will be something like "local MyVar".
Var := 33 ; Assigns 33 to a global variable, first creating the variable if necessary.
local x, y:=0, z ; Local variables must be declared in this mode, otherwise they would be assumed global.
; ...and so on.
}
|
|
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM |
|
| Back to top |
|
 |
Hardeep
Joined: 02 Jul 2006 Posts: 87
|
Posted: Thu Jul 19, 2007 3:58 pm Post subject: |
|
|
| Quote: | | in fact, using Local in this way sets all the others to global by default. |
Thats exactly why I am using it. The code posted above was just an example.
That was fast Chris...Thanks  |
|
| Back to top |
|
 |
Helpy Guest
|
Posted: Thu Jul 19, 2007 4:13 pm Post subject: |
|
|
| engunneer wrote: | | an even better answer is that it allows you to keep some variables local when the variables in the function are changed to global-by-default. | That's what I wrote, but probably in a non-explicit or confusing way. |
|
| Back to top |
|
 |
|