Mail Archives: djgpp-workers/2001/06/12/09:13:04
On Tue, 12 Jun 2001, Martin Stromberg wrote:
> > fcntl.c:23: warning: declaration of `index' shadows global declaration
> > make.exe[3]: *** [fcntl.o] Error 1
> > make.exe[2]: *** [all_subs] Error 2
> > make.exe[1]: *** [all] Error 2
> > make.exe: *** [subs] Error 2
> >
> > Renaming index to ind fixes the problem. Ok to commit?
>
> I'm not too happy with such changes. The variable is an index so it
> should be allowed to be named "index".
I disagree. Safe coding means that you try to stay away of potential
trouble even if meticulous analysis can prove that the trouble shouldn't
happen in that particular case. In other words, safe coding is about
restraint, not anarchy for the sake of it.
For the same reason, you would generally stop when the traffic light is
red even if there's no car anywhere in sight (and no cops ;-).
If you want a less far-fetched example, consider code that uses a local
variable called `fprintf'. ANSI C forbids that, but the only reason it
doesn't forbid `index' is that the latter is a non-ANSI function.
However, the danger and the potential trouble are the same.
> Sure it shadows another global named index. But that isn't a problem
> if we don't need to use that global.
The warning tells you that you could easily get a bug by rearranging code
in small ways.
- Raw text -