Why is 'int' used as just int and why not as std::int in C++?
Keywords such as int
and return
and the main()
function are all included in the C++ standard. std
does not mean that only those things are standardized. Instead, it refers to the things that are in the standard library (which, like keywords, is a part of the standard). Include files such as #include <vector>
are needed to use the standard library, but keywords can be used without any #include
s.
std::
is the namespace name of the Standard Library. But C++ has built-in types, and those are more fundamental. In fact, significant parts of the Standard Library are built using types like int
. You can see the chicken-and-egg problem if the Standard Library would depend on itself.
The types you mention are keywords. Keywords are not identifiers and therefore cannot belong to scopes or namespaces. During parsing of the program , keywords are found at an earlier stage than identifiers.
Changing the namespace of the program entry point (::main
currently) would mean all linkers everywhere have to be updated and so I doubt there would be any support for such a move. Also it would go against the principle that std
is for the standard library and not for user code, whereas the user writes the code that goes in main
.