How to punctuate [extern.names]/4?

61 views
Skip to first unread message

xskxzr

unread,
Jun 17, 2018, 2:00:01 PM6/17/18
to ISO C++ Standard - Discussion
[extern.names]/4:

Each function signature from the C standard library declared with external linkage is reserved to the implementation for use as a function signature with both extern "C" and extern "C++" linkage, or as a name of namespace scope in the global namespace.

Is it

... (for use as a function signature with both extern "C" and extern "C++" linkage, or as a name of namespace scope) in the global namespace.

or

... for use as a function signature with both extern "C" and extern "C++" linkage, (or as a name of namespace scope in the global namespace).

That is, is it allowed for use as a function signature with both extern "C" and extern "C++" linkage in non-global namespace?

xskxzr

unread,
Jun 17, 2018, 2:07:52 PM6/17/18
to ISO C++ Standard - Discussion
In addition, it seems a bit strange that 

with both extern "C" and extern "C++" linkage

uses "and", while

 or as a name of namespace scope in the global namespace

uses "or". 

xskxzr

unread,
Jun 18, 2018, 2:33:12 AM6/18/18
to ISO C++ Standard - Discussion
BTW, how can a function signature be used as a name?

Brian Bi

unread,
Jun 18, 2018, 5:59:00 PM6/18/18
to std-dis...@isocpp.org
I agree that the wording of this sentence is confusing. I would be surprised if they intended that you cannot declare a function called, say, printf, inside namespace xskzxr. I think you can open up an editorial issue on Github to fix the wording.

On Sun, Jun 17, 2018 at 11:33 PM, xskxzr <xsk...@gmail.com> wrote:
BTW, how can a function signature be used as a name?

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussion+unsubscribe@isocpp.org.
To post to this group, send email to std-dis...@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-discussion/.



--
Brian Bi

T. C.

unread,
Jun 18, 2018, 6:23:36 PM6/18/18
to ISO C++ Standard - Discussion
You definitely can't define an extern "C" function that way.

On Monday, June 18, 2018 at 5:59:00 PM UTC-4, Brian Bi wrote:
I agree that the wording of this sentence is confusing. I would be surprised if they intended that you cannot declare a function called, say, printf, inside namespace xskzxr. I think you can open up an editorial issue on Github to fix the wording.
On Sun, Jun 17, 2018 at 11:33 PM, xskxzr <xsk...@gmail.com> wrote:
BTW, how can a function signature be used as a name?

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussio...@isocpp.org.

To post to this group, send email to std-dis...@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-discussion/.



--
Brian Bi

Thiago Macieira

unread,
Jun 18, 2018, 7:09:57 PM6/18/18
to std-dis...@isocpp.org
On Monday, 18 June 2018 15:23:35 PDT T. C. wrote:
> You definitely can't define an extern "C" function that way.

Sure you can:

namespace xskzxr
{
extern "C" int printf(const char *not_format)
{
(void)not_format;
return 0;
}
}
See https://godbolt.org/g/3NQB4w

The function has the same external name as one found in the global namespace
or, consequently, any other namespace. From the C++'s point of view, this is
valid and simply causes the C++ function to be visible only from that
namespace and its associated (ADL) contexts. However, because the external
name is the same as the C library function, the above is not expected to work
in any existing system, as the C library always gets linked in to C++
applications.

--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center



T. C.

unread,
Jun 18, 2018, 7:18:45 PM6/18/18
to ISO C++ Standard - Discussion


On Monday, June 18, 2018 at 7:09:57 PM UTC-4, Thiago Macieira wrote:
On Monday, 18 June 2018 15:23:35 PDT T. C. wrote:
> You definitely can't define an extern "C" function that way.

Sure you can:

Sure, same way you can hold the ball and run in basketball. 


However, because the external
name is the same as the C library function, the above is not expected to work
in any existing system, as the C library always gets linked in to C++
applications.

 
That's the whole point. The library definitely meant to ban this.

Thiago Macieira

unread,
Jun 18, 2018, 7:37:09 PM6/18/18
to std-dis...@isocpp.org
Are you sure? The C++ standard does not guarantee you can call ::printf.

Does it say std::printf is extern "C"?

T. C.

unread,
Jun 18, 2018, 8:11:33 PM6/18/18
to ISO C++ Standard - Discussion


On Monday, June 18, 2018 at 7:37:09 PM UTC-4, Thiago Macieira wrote:
On Monday, 18 June 2018 16:18:45 PDT T. C. wrote:
> On Monday, June 18, 2018 at 7:09:57 PM UTC-4, Thiago Macieira wrote:
> > On Monday, 18 June 2018 15:23:35 PDT T. C. wrote:
> > > You definitely can't define an extern "C" function that way.
> >
> > Sure you can:
> Sure, same way you can hold the ball and run in basketball.
>
> > However, because the external
> > name is the same as the C library function, the above is not expected to
> > work
> > in any existing system, as the C library always gets linked in to C++
> > applications.
>
> That's the whole point. The library definitely meant to ban this.

Are you sure? The C++ standard does not guarantee you can call ::printf.

It does if you include the deprecated C++ header <stdio.h>.

Does it say std::printf is extern "C"?

As long as it wants to permit implementations to make std::printf extern "C" - and it certainly does ([using.linkage]p2) - it needs to reserve the name so that implementations that do so aren't broken by valid user code. Granted, [extern.names]p3 may have already done that ("Each name from the C standard library declared with external linkage is reserved to the implementation for use as a name with extern "C" linkage, both in namespace std and in the global namespace.").

Thiago Macieira

unread,
Jun 18, 2018, 11:16:26 PM6/18/18
to std-dis...@isocpp.org
On Monday, 18 June 2018 17:11:33 PDT T. C. wrote:
> > Are you sure? The C++ standard does not guarantee you can call ::printf.
>
> It does if you include the deprecated C++ header <stdio.h>.

That's not part of the C++ standard. You can include that header as much as
you can include <zlib.h>: it works if your system has that header.

> > Does it say std::printf is extern "C"?
>
> As long as it wants to permit implementations to make std::printf extern
> "C" - and it certainly does ([using.linkage]p2) - it needs to reserve the
> name so that implementations that do so aren't broken by valid user code.
> Granted, [extern.names]p3 may have already done that ("Each name from the C
> standard library declared with external linkage is reserved to the
> implementation for use as a name with extern "C" linkage, both in namespace
> std and in the global namespace.
> <https://timsong-cpp.github.io/cppwp/requirements#extern.names-3.sentence-1>
> ").

Thanks, that does settle that it's reserved.

T. C.

unread,
Jun 18, 2018, 11:20:03 PM6/18/18
to ISO C++ Standard - Discussion


On Monday, June 18, 2018 at 11:16:26 PM UTC-4, Thiago Macieira wrote:
On Monday, 18 June 2018 17:11:33 PDT T. C. wrote:
> > Are you sure? The C++ standard does not guarantee you can call ::printf.
>
> It does if you include the deprecated C++ header <stdio.h>.

That's not part of the C++ standard.
 
It is. See [depr.c.headers].


xskxzr

unread,
Jun 18, 2018, 11:23:55 PM6/18/18
to ISO C++ Standard - Discussion
So what about C++ linkage?

Do you mean [extern.names]/4 is interpreted as the latter case? i.e. each function signature from the C standard library declared with external linkage is reserved everywhere?
Reply all
Reply to author
Forward
0 new messages