I get an error saying that 'buf' shadows a global declaration, but I go to take it out and I get more errors. For example, I take it out of do_who in act_info.c of SWFotE 1.2, and I get errors in passing stuff from incompatable pointer type. Any suggestions, or do you need more info?
'buf' shadows a global declaration
Posted by Miked on Wed 13 Jul 2005 10:07 AM — 12 posts, 45,207 views.
As long as you take out the shadowed declaration all should be fine.
Well my example might not be very pretty or very acurate, but you should remove where the variable has been declared for the second time within that function.
Now, there are other more sinister shaddowed declarations, ones that deal with librarys and such, some more detail would be needed to see what exaclty you have going on.
void do_nothing(*argument)
char declare[MIL]
if (something and something)
char declare[MIL] //remove this one
Well my example might not be very pretty or very acurate, but you should remove where the variable has been declared for the second time within that function.
Now, there are other more sinister shaddowed declarations, ones that deal with librarys and such, some more detail would be needed to see what exaclty you have going on.
This issue generally means that you have a variable called "buf" declared somewhere as a global variable(usually) and that the compiler is complaining because it is not obvious which one to use inside the function: the local one, or the global one. Since "buf" is very common as a local variable, I wouls likely change the global one.
*nod* A common global def would be "log_buf" but I think buf is too common to be used as a global def.
I didn't realize shadowing is an error-inducing problem (although it can make for very hard-to-track bugs...) What the compiler is supposed to do is use the local-most variable - nice compilers emit warnings, not errors, about shadowing. This might be a C++ vs C thing, though; I haven't coded in straight C for a while and have no reason to. :-)
I beleive that it is produced as an error by the pedantic flag, but I could be wrong.
Even so, when I compile I use the highest warning levels, pedantic etc., and I've never gotten that error.
I just wrote the following:
And tested it:As expected, we get 4. Didn't even get a warning about a shadowing... strange. Note that it's all C, not C++, for what it's worth.
I just wrote the following:
Quote:
#include <stdio.h>
int i = 3;
int main()
{
int i = 4;
printf("Hello there: %d\n", i);
return 0;
}
And tested it:
dhaley@muri5 ~/tmp
$ gcc -Wall --pedantic test.c -o test
dhaley@muri5 ~/tmp
$ ./test
Hello there: 4
dhaley@muri5 ~/tmp
$
Quote:
Even so, when I compile I use the highest warning levels, pedantic etc., and I've never gotten that error.
Even so, when I compile I use the highest warning levels, pedantic etc., and I've never gotten that error.
-Wall does not warn about shadowing. You need to turn on -Wshadow to do that.
Even so, that is a warning, not an error, so I'm not sure where this error is coming from. Unless of course the OP really meant warning, not error.
Could have the flag that turns warning into errors on. Can't remember what it is off the top of my head, though.
[edit]
I think it's -Werror
[edit]
I think it's -Werror
With -Werror it will not compile with a warning.
Right... -Werror makes it treat warnings as errors, like Greven said. :)