This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: Myserious warning message
Werner LEMBERG <wl@gnu.org> writes:
>> > I get a very mysterious warning message while compiling ftview.c:
>> >
>> > In file included from src/ftview.c:20:
>> > /home/ft/freetype2/include/freetype/cache/ftcmanag.h:119:
>> > warning: declaration of `index' shadows global declaration
>> >
>> > There is no global declaration of an `index' variable AFAIK (the
>> > function declaration of `index' in string.h is not triggering the
>> > warning -- commenting out the line changes nothing, as expected).
>>
>> Removing that line gives:
>>
>> In file included from src/ftview.c:20:
>> /home/ft/freetype2/include/freetype/cache/ftcmanag.h:119:
>> warning: declaration of `index' shadows a global declaration
>> <built-in>:0: warning: shadowed declaration is here
>>
>> Which shows that index is also a builtin - and adding -fno-builtin
>> avoids the warning completly:
>
> Thanks for the explanation! But how shall I know this? In my gcc
> 2.95 info pages, `index' isn't mentioned as a built-in function.
This is fixed for GCC 3.1. GCC 3.1 has:
@node Other Builtins
@section Other built-in functions provided by GCC
...
Outside strict ISO C mode, the functions @code{alloca}, @code{bcmp},
@code{bzero}, @code{index}, @code{rindex}, @code{ffs}, @code{fputs_unlocked},
@code{printf_unlocked} and @code{fprintf_unlocked} may be handled as
built-in functions. All these functions have corresponding versions
prefixed with @code{__builtin_}, which may be used even in strict C89
mode.
> Anyway, I strongly suggest to change the warning message to something
> like
>
> declaration of `index' shadows built-in function with same name
>
> Another question is why built-in function names clobber the variable
> namespace...
There's no separate variable and function name space in C. Try:
extern int index (void);
int index;
$ gcc -Wall t.c
t.c:3: `index' redeclared as different kind of symbol
t.c:2: previous declaration of `index'
Therefore the warning is usefull and valid!
Andreas
--
Andreas Jaeger
SuSE Labs aj@suse.de
private aj@arthur.inka.de
http://www.suse.de/~aj