Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ SMAUG
➜ SMAUG coding
➜ 'buf' shadows a global declaration
'buf' shadows a global declaration
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Miked
USA (30 posts) Bio
|
Date
| Wed 13 Jul 2005 10:07 AM (UTC) |
Message
| 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? | Top |
|
Posted by
| Robert Powell
Australia (367 posts) Bio
|
Date
| Reply #1 on Wed 13 Jul 2005 10:48 AM (UTC) |
Message
| As long as you take out the shadowed declaration all should be fine.
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. |
Just a guy having a bit of fun. Nothing more, nothing less, I do not need I WIN to feel validated. | Top |
|
Posted by
| Greven
Canada (835 posts) Bio
|
Date
| Reply #2 on Wed 13 Jul 2005 02:15 PM (UTC) |
Message
| 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. |
Nobody ever expects the spanish inquisition!
darkwarriors.net:4848
http://darkwarriors.net | Top |
|
Posted by
| Zeno
USA (2,871 posts) Bio
|
Date
| Reply #3 on Wed 13 Jul 2005 03:15 PM (UTC) |
Message
| *nod* A common global def would be "log_buf" but I think buf is too common to be used as a global def. |
Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #4 on Wed 13 Jul 2005 05:05 PM (UTC) |
Message
| 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. :-) |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Greven
Canada (835 posts) Bio
|
Date
| Reply #5 on Wed 13 Jul 2005 06:21 PM (UTC) |
Message
| I beleive that it is produced as an error by the pedantic flag, but I could be wrong. |
Nobody ever expects the spanish inquisition!
darkwarriors.net:4848
http://darkwarriors.net | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #6 on Wed 13 Jul 2005 06:40 PM (UTC) |
Message
| 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:
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
$
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. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Raz
(32 posts) Bio
|
Date
| Reply #7 on Thu 14 Jul 2005 03:20 PM (UTC) Amended on Thu 14 Jul 2005 03:21 PM (UTC) by Raz
|
Message
|
Quote: 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. |
-Raz
C++ Wiki: http://danday.homelinux.org/dan/cppwiki/index.php | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #8 on Thu 14 Jul 2005 04:47 PM (UTC) |
Message
| 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. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Greven
Canada (835 posts) Bio
|
Date
| Reply #9 on Thu 14 Jul 2005 07:46 PM (UTC) Amended on Thu 14 Jul 2005 07:49 PM (UTC) by Greven
|
Message
| 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 |
Nobody ever expects the spanish inquisition!
darkwarriors.net:4848
http://darkwarriors.net | Top |
|
Posted by
| Robert Powell
Australia (367 posts) Bio
|
Date
| Reply #10 on Fri 15 Jul 2005 12:30 AM (UTC) Amended on Fri 15 Jul 2005 12:33 AM (UTC) by Robert Powell
|
Message
| With -Werror it will not compile with a warning. |
Just a guy having a bit of fun. Nothing more, nothing less, I do not need I WIN to feel validated. | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #11 on Fri 15 Jul 2005 12:43 AM (UTC) |
Message
| Right... -Werror makes it treat warnings as errors, like Greven said. :) |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
34,739 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top