0

In clang's standard library, what do the _ and __ on variables mean? Here is a part of string_view.

    inline 
       void __throw_out_of_range(const char*__msg)
   {
      throw out_of_range(__msg);
   }

    // __str_find_first_not_of
    template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
    inline _SizeT
       __str_find_first_not_of(const _CharT *__p, _SizeT __sz,
          const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT

gahhu
  • 31
  • 3

1 Answers1

2

_ and __ are just part of the identifier. They don't have any other special meaning.

However, identifiers containing a double underscore or starting with an underscore followed by an upper-case letter are reserved for the standard library. The user code is not allowed to declare them or define them as macro.

The standard library uses only such reserved identifiers for internal use to make sure that it doesn't interfere with any user code that is supposed to be valid.

For example this is a valid program:

#define sz
#define SizeT
#include<string_view>
int main() {}

If the standard library implementation shown in the question was using just sz and SizeT instead of __sz and _SizeT, this would fail to compile.

However

#define __sz
#define _SizeT
#include<string_view>
int main() {}

is not a valid program and therefore it is ok if it fails to compile.

user17732522
  • 53,019
  • 2
  • 56
  • 105