Veggie
Veggie

Reputation: 407

Does the C++ Spec treat the std library special?

It was my impression that std library was not special to a C++ compiler, just special because every vendor ships an implementation of it, and otherwise it's just code written in C++ usable in C++ just like any other code written in C++.

I have seen a few places that seem to disagree with this, such as how user-defined literal suffixes must begin with an underscore because "the suffixes that do not begin with the underscore are reserved for the literal operators provided by the standard library". https://en.cppreference.com/w/cpp/language/user_literal

Does the spec really have different rules for the std library than for other C++ code to be compiled? Are C++ compilers hard-coded to recognize code in std library and "do something different"?

This is really upsetting my internal image of how this whole system works together...

Upvotes: 1

Views: 143

Answers (1)

Asteroids With Wings
Asteroids With Wings

Reputation: 17454

The library is mostly as you describe, though there are exceptions.

The problem with literals that you mention may be a defect. Even if this is so, however, a name clash within the implementation is completely avoidable in practice, since it's a single group of people writing it.

Furthermore, some standard library features actually cannot be implemented without compiler support.

So it's a bit of a mixed bag.

Upvotes: 2

Related Questions