|
'buf' shadows a global declaration
|
Reply to this subject
Start a new subject
 
Refresh page
| Posted by |
Miked
USA (30 posts) bio
|
| Date |
Wed 13 Jul 2005 10:07 AM (UTC) [ quote
] |
| 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 (349 posts) bio
|
| Date |
Reply #1 on Wed 13 Jul 2005 10:48 AM (UTC) [ quote
] |
| 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. |
EldhaMUD Game Developments
The_Fury: Lead Developer, Head Coder
http://fury.eldhamud2.org
| top |
|
| Posted by |
Greven
Canada (835 posts) bio
|
| Date |
Reply #2 on Wed 13 Jul 2005 02:15 PM (UTC) [ quote
] |
| 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,867 posts) bio
Moderator |
| Date |
Reply #3 on Wed 13 Jul 2005 03:15 PM (UTC) [ quote
] |
| 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
Moderator |
| Date |
Reply #4 on Wed 13 Jul 2005 05:05 PM (UTC) [ quote
] |
| 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) [ quote
] |
| 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
Moderator |
| Date |
Reply #6 on Wed 13 Jul 2005 06:40 PM (UTC) [ quote
] |
| 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) [ quote
] 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
Moderator |
| Date |
Reply #8 on Thu 14 Jul 2005 04:47 PM (UTC) [ quote
] |
| 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) [ quote
] 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 (349 posts) bio
|
| Date |
Reply #10 on Fri 15 Jul 2005 12:30 AM (UTC) [ quote
] Amended on Fri 15 Jul 2005 12:33 AM (UTC) by Robert Powell
|
| Message |
| With -Werror it will not compile with a warning. |
EldhaMUD Game Developments
The_Fury: Lead Developer, Head Coder
http://fury.eldhamud2.org
| top |
|
| Posted by |
David Haley
USA (3,881 posts) bio
Moderator |
| Date |
Reply #11 on Fri 15 Jul 2005 12:43 AM (UTC) [ quote
] |
| 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.
5,231 views.
Reply to this subject
Start a new subject
 
Refresh page
top
Comments to:
Gammon Software support
Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )