Decorate C prototypes

tom fogal tfogal@alumni.unh.edu
Sun May 3 23:13:00 GMT 2009


Mark Mitchell <mark@codesourcery.com> writes:
> Martin Sebor wrote:
> 
> >> 2. We should verify that the compiler accepts
> >>
> >>   extern "C" void abort(void);
> >>   namespace std {
> >>     extern "C" void abort(void) throw();
> >>   }
> 
> > gcc 4.3.1 (the latest I have access to at the moment) does accept
> > this even though it's ill-formed according to [except.spec], p2:
> > 
> >   If any declaration of a function has an exception-specification,
> >   all declarations, including the definition and an explicit
> >   specialization, of that function shall have an exception-
> >   specification with the same set of type-ids.
> 
> Yes, but I never remember if the standard explicitly says that the two
> declarations above are for the same function.  In other words, how do
> namespaces interact with extern "C"?
[snip]
> But, does the standard actually say that "::abort" and "std::abort"
> are the same function in the example above?  Or are they different
> functions which just happen to end up with the same mangled name?

I was still skeptical after a response from Martin (sorry, for got to
CC you), and he quoted an exact section, so I actually checked that
part of the standard.

In the clause he quoted to me, [dcl.link], p6, there is explicit
wording to make namespaces irrelevant.  Here's that clause without the
example:

  At most one function with a particular name can have C language
  linkage. Two declarations for a function with C language linkage
  with the same function name (ignoring the namespace names that
  qualify it) that appear in different namespace scopes refer to the
  same function. Two declarations for an object with C lan- guage
  linkage with the same name (ignoring the namespace names that qualify
  it) that appear in different namespace scopes refer to the same
  object. [Note: because of the one definition rule (3.2), only one
  defini- tion for a function or object with C linkage may appear in
  the program; that is, such a function or object must not be defined
  in more than one namespace scope.

note the "ignoring the namespace names that qualify it", which was
critical (to me) for understanding this issue.

Best,

-tom



More information about the Libstdc++ mailing list