Date: Mon, 13 Oct 2014 20:49:56 +0200 From: Szabolcs Nagy <nsz@...t70.net> To: musl@...ts.openwall.com Subject: Re: [PATCH] Convert some is* macros to inline functions * Rich Felker <dalias@...c.org> [2014-10-13 14:06:22 -0400]: > On Mon, Oct 13, 2014 at 09:00:56PM +0300, Sergey Dmitrouk wrote: > > Current headers do not conform to C++ when included as <header.h>, and > > that's what I'm trying to fix. > > > > Would you consider a version that uses inline functions only when > > __cplusplus is defined? There is already 'extern "C"', so I guess it > > makes sense. > > Suppressing the macros for C++ would be acceptable if this is required > (it's not clear to me; my understanding was that it's only required > for the <c_____> headers, not the <______.h> ones, and that the > wrappers for the former already take care of removing the macros). The > external inline functions are probably not acceptable; there are all > sorts of ugly issues with extern inline function support that I don't > want to deal with. only providig the macros #ifndef __cplusplus makes sense (but only do it in the 26 c headers the c++ standard talks about posix allows macro definitions for all functions in posix headers) the c++ standard could be more explicit about this incompatibility with c: it states the requirement in a note for the <cname> headers and then defines the semantics for the <name.h> headers in terms of the <cname> one c++14 126.96.36.199 [headers] 4 Except as noted in Clauses 18 through 30 and Annex D, the contents of each header cname shall be the same as that of the corresponding header name.h, as specified in the C standard library (1.2) or the C Unicode TR, as appropriate, as if by inclusion. In the C++ standard library, however, the declarations (except for names which are defined as macros in C) are within namespace scope (3.3.6) of the namespace std. It is unspecified whether these names are first declared within the global namespace scope and are then injected into namespace std by explicit using-declarations (7.3.3). 5 Names which are defined as macros in C shall be defined as macros in the C++ standard library, even if C grants license for implementation as functions. [ Note: The names defined as macros in C include the following: assert, offsetof, setjmp, va_arg, va_end, and va_start. -- end note ] 6 Names that are defined as functions in C shall be defined as functions in the C++ standard library.^175 7 Identifiers that are keywords or operators in C++ shall not be defined as macros in C++ standard library headers.^176 8 D.5, C standard library headers, describes the effects of using the name.h (C header) form in a C++ program.^177 175) This disallows the practice, allowed in C, of providing a masking macro in addition to the function prototype. The only way to achieve equivalent inline behavior in C++ is to provide a definition as an extern inline function. 176) In particular, including the standard header <iso646.h> or <ciso646> has no effect. 177) The ".h" headers dump all their names into the global namespace, whereas the newer forms keep their names in namespace std. Therefore, the newer forms are the preferred forms for all uses except for C++ programs which are intended to be strictly compatible with C. ... c++14 D.5 [depr.c.headers] 2 Every C header, each of which has a name of the form name.h, behaves as if each name placed in the standard library namespace by the corresponding cname header is placed within the global namespace scope. It is unspecified whether these names are first declared or defined within namespace scope (3.3.6) of the namespace std and are then injected into the global namespace scope by explicit using-declarations (7.3.3).
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.