--- Begin Message ---
- To: Vaclav Ovsik <vaclav.ovsik@i.cz>
- Cc: Bernd Zeimetz <bernd@bzed.de>, debian-mentors@lists.debian.org
- Subject: Re: RFS: ustr (updated package)
- From: James Antill <james@and.org>
- Date: Mon, 05 Nov 2007 20:18:24 -0500
- Message-id: <m3bqa8qihr.fsf@code.and.org>
- In-reply-to: <20071105144030.GA30512@bobek.pm.i.cz> (vaclav.ovsik@i.cz's message of "Mon, 5 Nov 2007 15:40:30 +0100")
- References: <20071031171528.GB19411@bobek.pm.i.cz> <47291F6A.3040009@bzed.de> <m3odeesjrj.fsf@code.and.org> <472998C8.3040602@bzed.de> <m3hck6rtl2.fsf@code.and.org> <472CA38D.201@bzed.de> <20071105144030.GA30512@bobek.pm.i.cz>
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 ---