Why am I getting the "Uninflated Local Variable" warning? (C ++)
When I do something like
#include<iostream>intmain(){
int x;
return0;
}
I'm getting a warning that x is an unaccepted local variable (I suppose because I created a variable and then didn't use it), why is this giving me a warning though?
Plus, the code gets messy and hard to understand, not to mention programmers don't usually define variables they don't need, so it's kind of "is this really what you meant?" warning.
Because usually people don't create unintended variables on purpose. Therefore, if there is an undescribed variable in the program, it is usually a sign that you have an error somewhere, and the compiler will warn you about it.
voidsome_func(){
int a, b, c, d, e;
...
do_something_with(a);
do_something_with(b);
do_something_with(c);
do_something_with(d);
do_something_with(c); // after hours of reading code, e looks like c: BUG!!
}
it also lets you know what if you think you are using a variable and you don't know. assuming you created the variable for some reason, and maybe you forgot to use it somewhere.
Or maybe they expected its constructor to have a side effect when used in scope, and its destructor a different side effect when extending it, and doesn't want the compiler to be as "useful" as people know best. when it comes with the intention of another code.