ID:260467
 
Applicable Configuration:
BYOND Version: 411.976
Operating System: Windows XP
Web Browser: Firefox
Game/Hub(s): Dream Maker

Descriptive Problem Summary:
When using the ++ operator on a variable, without doing anything else to it, will yield the following: "warning: variable defined but not used". yet it is used in the following statement.

Code Snippet (if applicable) to Reproduce Problem:
var/hello=0
hello++ //Adds 1 to hello.
// hello :warning: variable defined but not used


Expected Results:
For no warning to display.
Actual Results:
A warning displays telling me hello has no effect.
Does the problem occur:
Every time? Or how often? Yes

Workarounds:
var/hello=0
hello+=1 //Also ads 1 to hello but does not give an error.


Please correct me if I'm wrong, but isn't this the use of the ++ operator?
+=1 should really give the same warning.

The problem is that you're doing stuff to the variable, yes, but you're not then using the variable anywhere else. Consider, for example:

proc/whatever
world << "Whatever called!"
var/useless=1

for(var/i=1, i<5, i++)
world << i
useless+=4

world << "Well, that's that"

useless*=2


Much as you're doing operations on 'useless', you're not actually using it for anything.
In response to Jp
That is very misleading though. Maybe the output should be a little different.
In response to Shlaklava
Not really. The variable is defined, but not used. What is confusing about that o.O
In response to Jamesburrow
The thing is, it IS used, just because it's not used in any useful way shouldn't be up to the compilers' descression.

I think it should only give this error when the such happens.
var/NeverUsed=0
world<<"I like pie!"
return 1


It shouldn't show the error as long as I'm doing some mathmatical function to it, even if it is useless.
In response to Flame Sage
No, it has to actually be used to be used. Being in a mathematical function is not enough.
var
useless
proc
useless()
useless+=1

Although it has a mathematical function, it is not actually used anywhere in the code.
However, this:

var
useful
proc
useful()
useful+=1
world<<useful
//or
var
useful
proc
useful()
useful+=1
var/usefulness=useful*2
world<<usefulness

Just holding a value that changes is not enough to be considered used.
Besides, its just a warning to let you know there is a variable that although defined has no actual effect on anything. Its not an error that keeps it from running, but a helpful warning.

A variable is defined as not being used if it is not outputted in any way, is not found in any if() statement, is not used in the assignment of another variable, etc. It has to have an effect on the code somewhere to be deemed as having a use.
In response to Jamesburrow
Oh ok, I get what your saying but...
I still think it shouldn't display a warning. oh well :P

In other news, then
var/useless
useless+=1

should yield a warning, but doesn't.
In response to Flame Sage
The fact that you bother to define it then put something into it qualifies it as being used, I would think. So no warning is needed.
In response to digitalmouse
digitalmouse wrote:
The fact that you bother to define it then put something into it qualifies it as being used, I would think. So no warning is needed.

So... your agreeing with me?
What do the developers think about this?
I would assume it's only use would be something like
var/a=0
var/b=0
var/c=0
var/d=0
d=a+b
//When I compile, it will say C was never used
In response to Flame Sage
Not sure about the case you mentioned above, but doing a 'c=0' means you used it to set it to 0 - atleast in my thinking. So I don't believe it is an error, per-se.

Though I can understand if the compiler is smart enough to notice that you never use the declaration elsewhere in your code, and warns you about it. Nothing wrong in that.
In response to Flame Sage
Flame Sage wrote:
I would assume it's only use would be something like
> var/a=0
> var/b=0
> var/c=0
> var/d=0
> d=a+b
> //When I compile, it will say C was never used
>


it will say that both c and d are not used. a and b are used to compute the value of d, but the value of d is never used. assignment to a variable is not considered use. if assignment was considered use, all of the variables would be used because you assigned zero to each of them as you declared them.

for example, the line:
d += 1


does constitute use, but not because you're assigning to d. since that line is equivalent to saying d = d + 1, you're using the value of d in the computation and that is why it uses d.

while d++ would have the same effect as d += 1, it is technically different, and that's probably why these two examples have the same effect but only one has a warning.
In response to Flame Sage
This is not a bug. It was moved here (though not by me) because it's at best a feature request. ++ is not identical internally to +=1, so there are slight differences to account for. Even if it was, though, that's moot. The fact that one case gives you a helpful warning while another case gives you no warning even though neither situation is harmful, is absolutely fine. It doesn't cause a game to malfunction or to compile incorrectly.

Also, such a feature would be difficult to implement since only Dan really understands how this warning works.

Lummox JR