[cfe-dev] Use of double underscores in identifiers in libc++

Howard Hinnant hhinnant at apple.com
Thu May 13 06:53:13 PDT 2010


On May 13, 2010, at 2:29 AM, Alex Rosenberg wrote:

> Maybe I'm paranoid, but I'm predicting identifier clashes with  
> intrinsics due to the use of double underscores.
> 
> [lib.global.names] touches on this, but my expectation from  
> established convention is that the library should use identifiers that  
> start with a single underscore and leave the double underscore  
> identifiers for use in the compiler itself (and platform-specific  
> compiler headers like altivec.h).

It is true that the double underscore names may clash with compiler intrinsics.  This is just one of many reasons why it is very difficult to make a 100% portable std C++ library.  The std lib exists so that its clients can write more portable code.  That doesn't mean the std lib itself is necessarily portable.

"The implementation" mentioned in [global.names] refers to the compiler/std-lib combination.  From our client's point of view it really doesn't matter if __foo is reserved for the compiler or for the std lib.

libc++ always uses one of:

1.  __[a-z]
2.  _[A-Z]
3.  An identifier that is explicitly reserved by the (draft) standard.

This convention is not unusual with respect to other std lib implementations.

-Howard





More information about the cfe-dev mailing list