delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2001/06/12/09:36:24

X-Authentication-Warning: acp3bf.physik.rwth-aachen.de: broeker owned process doing -bs
Date: Tue, 12 Jun 2001 15:36:13 +0200 (MET DST)
From: Hans-Bernhard Broeker <broeker AT physik DOT rwth-aachen DOT de>
X-Sender: broeker AT acp3bf
To: djgpp-workers AT delorie DOT com
Subject: Re: [PATCH] gcc-3.0 related fix for src/libc/posix/fcntl/fcntl.c
In-Reply-To: <200106121251.OAA13656@lws256.lu.erisoft.se>
Message-ID: <Pine.LNX.4.10.10106121523320.1792-100000@acp3bf>
MIME-Version: 1.0
Reply-To: djgpp-workers AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp-workers AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On Tue, 12 Jun 2001, Martin Stromberg wrote:

> Andris said:
[...]
> > 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". 

In other circumstances: maybe yes. But the library build is delibarately
very picky on its warnings. -Wshadow, which is causing this
warning-turned-error, is a useful warning in lots of situations. The false
warnings it may create are obvious and easy to handle, so I'm in favour of
it.

> Sure it shadows another global named index. But that isn't a problem
> if we don't need to use that global.

The problem is that the compiler can't know what we wanted --- since it's
not a telepath. It can only see the code might not be doing what the
reader would think it does, so the warning is justified.

Actually, the real problem here was caused by whoever chose to name that
global function 'index', in the first place --- it's one of the worst
cases of namespace pollution I've ever come across.  It's also the root of
an old C language FAQ: Unix linkers don't complain about an un-initialized
global definition of variable 'index' if the header declaring the
like-named function isn't included. The program just crashes at run time,
in one of several very mysterious ways. This reliably manages to
completely puzzle every Unix C newbie out of his/her wits, as (s)he comes
across it for the first time.

-- 
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019