[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

gcc false warning about static ident in inline function?



Hi,
discussion about warning emited by gcc 4.3 from experimental runs on the
debian-mentors. We have a code (from upstream), that emits a warning and this
is probably against a propositions in C99 std.


zito@sid:~/inline$ aptitude search -F %25p%65V ~i~n^gcc
gcc            4:4.3-20070902-0
gcc-4.1        4.1.2-17
gcc-4.1-base   4.1.2-17
gcc-4.2        4.2.2-3
gcc-4.2-base   4.2.2-3
gcc-4.3        4.3-20071020-1
gcc-4.3-base   4.3-20071020-1
gcc-4.3-doc    4.3-20071020-1
zito@sid:~/inline$ gcc -c -Wall x.c
x.c: In function 'ustr_xi__pow2':
x.c:4: warning: 'map_big_pow2' is static but declared in inline function 'ustr_xi__pow2' which is not static
x.c:5: warning: 'map_pow2' is static but declared in inline function 'ustr_xi__pow2' which is not static
x.c:8: warning: 'map_big_pow2' is static but used in inline function 'ustr_xi__pow2' which is not static
x.c:10: warning: 'map_pow2' is static but used in inline function 'ustr_xi__pow2' which is not static
zito@sid:~/inline$ cat x.c

extern inline int ustr_xi__pow2(int use_big, unsigned char len)
{
  static const unsigned char map_big_pow2[4] = {2, 4, 8, 16};
  static const unsigned char map_pow2[4] = {0, 1, 2, 4};

  if (use_big)
    return (map_big_pow2[len & 0x03]);

  return (map_pow2[len & 0x03]);
}


Is this really a bug in the gcc? (So should I report it as a bug?) Please comment.
Thanks.
-- 
Zito
--- Begin Message ---
Vaclav Ovsik <vaclav.ovsik@i.cz> writes:

> I have setup gcc-4.3 from experimental on a sid xen guest.
> The warning is emitted for example on following (simplified) code:
>
>     extern inline char func( int arg )
>     {
>       static const char foomap[4] = {2, 4, 8, 16};
>
>       return foomap[arg & 3];
>     }

 Yes, from the link Bernd provided the warning is emitted basically
for anything that uses the static keyword. The above is correct
though, IMO, as is:

     extern inline char func( int arg )
     {
       static const char foomap[] = "abc";

       return foomap[arg & 3];
     }

> I have red several times the ISO paragraph :). It seems to me, that
> paragraph applies to this situation.
> IMHO foomap is `reference to an identifier with internal linkage'.
> Or no? :)

 From ISO 9899:1999 6.2.2 Linkages of identifiers:

 #1
An identifier declared in different scopes or in the same scope more
than once can be made to refer to the same object or function by a
process called linkage. There are three kinds of linkage: external,
internal, and none.

 #2
If the declaration of a file scope identifier for an object or a
function contains the storage-class specifier static, the identifier
has internal linkage.
[...]
 #6
The following identifiers have no linkage: an identifier declared to
be anything other than an object or a function; an identifier declared
to be a function parameter; a block scope identifier for an object
declared without the storage-class specifier extern.

...from that #2 doesn't apply because the identifier isn't at file
scope, and so the last part of #6 does apply.

 Also it's "well known" that in:

void foobar(void)
{
  const char *const foo   = "abcd";
  static const char bar[] = "abcd";
}

...foo and bar do the same thing, point to some constant data, but bar
is the better version.
 As with foo you have a allocated two objects (the pointer being the
second object), and have to use/manage them both, but with bar you
have just "named" a single object.

-- 
James Antill -- james@and.org
C String APIs use too much memory? ustr: length, ref count, size and
read-only/fixed. Ave. 44% overhead over strdup(), for 0-20B strings
http://www.and.org/ustr/

--- End Message ---

Reply to: