On Sun, 04 Dec 2005, Sidney Markowitz uttered the following:
> Nix wrote:
>> - All identifiers that begin with an underscore are
>> always reserved for use as macros and as identifiers
>> with file scope in both the ordinary and tag name
>> spaces.
>>
>> libspamc falls foul of the second clause; its identifiers should indeed
>> probably lose the underscore.
>
> No, when the Standard says they are reserved for use as macros and as
> identifiers with file scope, it means that the compiler implementors
> cannot use them for other things because they are reserved for uses such
> as you see in libspamc.c, in which an ordinary user of C uses them as
> the names of static functions which are visible only in the file (i.e.,
> have file scope).
Um, `reserved for use as {X}...' means `you cannot use them as {X}
because they are reserved, but you can use them for other things'.
Note the phrasing of the previous clause, which reserves
e.g. identifiers beginning with underscores and uppercase letters `for
any use'; that doesn't mean you can use them for anything at all, it
means you *can't*.
The implementation on glibc-using platforms, for instance, uses
identifiers such as _GLOBAL_OFFSET_TABLE_ and _dl_start and _setjmp and
_dl_mcount_wrapper_check and _IO_new_* and _nl_current_default_domain
and, oh, *lots* of others. These identifiers are treated as reserved by
a group of implementors known to be totally paranoid about namespace
correctness; I think it's wise to assume that they *are*, therefore,
reserved.
You can name a local variable _dl_start on a glibc platform and
everything will work fine. Call a global function that and suddenly you
can't statically link your program anymore because you've stamped on a
reserved identifier in use by that implementation. Call a static
function that and... interesting things will happen if you try to
dlopen() anything. Weird random results, yep, looks like undefined
behaviour to me.
> libspamc is using those identifiers exactly as they are supposed to be
> used. Unless I overlooked any, all of them are declared as static
> functions with file scope.
Yes. Thus they are reserved, static functions with file scope being
`identifiers... with file scope'.
> The Standard gives us the ability to name things that are not visible
> outside the file with no fear that the name is being used for an
> incompatible purpose in any included system header.
>
> See Section 7.1.3 page 112 "Rationale for International Standard—
> Programming Languages— C"
> http://www.open-std.org/jtc1/sc22/wg14/www/C99RationaleV5.10.pdf
Woo, 7.1.3 line 20 of the Rationale disagrees with the Standard,
brilliant. Either `reserved for... use' is used to mean two things with
opposite meaning in two consecutive paragraphs of the Standard, or the
Rationale is wrong when it doesn't mention the second clause of 7.1.3.1.
Thankfully the Rationale is not normative so we can ignore it and follow
the Standard instead.
--
`Y'know, London's nice at this time of year. If you like your cities
freezing cold and full of surly gits.' --- David Damerell