Inconsistent increment/decrement on uninitialized variables

Report problems with documented functionality
bj8tr
Posts: 14
Joined: 23 Feb 2014, 14:02

Inconsistent increment/decrement on uninitialized variables

23 Feb 2014, 14:41

Code: Select all

DoSomething(tv){
	MsgBox,, test.ahk, Did something, testVar2 = %tv%
}

test(){
	++testVar1 ; testVar1 now == 1
	(++testVar2) ; testVar2 blank
	ListVars
	Pause ; Press Pause key to resume...
	if (++testVar2 > 0) ; doesn't DoSomething
		DoSomething(testVar2)
	testVar2 := 0
	(++testVar2) ; testVar2 now == 1
	ListVars
	Pause
	if (++testVar2 > 1)
		DoSomething(testVar2) ; does DoSomething, and testVar2 now == 2
}
The above code demonstrates how an uninitialized/blank variable increments (or decrements -- take my word for it ;) differently depending on whether it's parenthesized or not. This is since v1.1.07.01 at least, and continues through the current release version.

What am I missing?
lexikos
Posts: 9679
Joined: 30 Sep 2013, 04:07
Contact:

Re: Inconsistent increment/decrement on uninitialized variab

23 Feb 2014, 15:58

bj8tr wrote:What am I missing?
The documentation?
Due to backward compatibility, the operators ++ and -- treat blank variables as zero, but only when they are alone on a line;
Source: Variables and Expressions
bj8tr
Posts: 14
Joined: 23 Feb 2014, 14:02

Re: Inconsistent increment/decrement on uninitialized variab

23 Feb 2014, 16:11

Darn, sorry about that. Now that you mention it, I remember seeing that long ago when I first ran into this issue, and checked the documentation.

Guess I needed a dose of foot-in-mouth to get me back into good habits. And to think, I *did* search the forums for previous discussion on this topic. Probably missed it here, too.

Will v2 dispose of this particular backwards compatibility, as it has/will many others? I'm sure there's a use for it, though it seems pretty esoteric.
lexikos
Posts: 9679
Joined: 30 Sep 2013, 04:07
Contact:

Re: Inconsistent increment/decrement on uninitialized variab

23 Feb 2014, 23:19

Yes.
v2-changes wrote::= += -= *= /= ++ -- have consistent behaviour regardless of whether they are used on their own or combined with other operators, such as with x := y, y += 2.

Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 4 guests