deadLock
deadLock

Reputation: 400

Why is 'int' used as just int and why not as std::int in C++?

Unlike everything is standardized in current C++, are there any specific reasons to leave int, char, ...., main() and others from it. (Not talking of +,-,%,.. because they aren't language-specific)

Why is it not like:

std::int std::main(std::int argc, std::char *argv[])
{
    //Sample C++ code (incorrect with current standards though)
    std::return 0;
}

Isn't standardization incomplete with them out of std scope?

What I believe is, they are basic components which occurs everywhere when writing a program, whether simple or complex. They are not included in the standardization, just to follow the DRY principle.

Upvotes: 12

Views: 7146

Answers (4)

Catastrophe
Catastrophe

Reputation: 350

As far as I know. Int is a primitive (primary) data type. Primary data types are already defined in the programming languages also called primitive or in-built data types. "int" data type is one of them. In some of the languages, you can see some of the byte, short, int, long, char, float, double or boolean keywords used as themselves.

Hope I was helpful.

Upvotes: 0

MSalters
MSalters

Reputation: 179787

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.

Upvotes: 11

VLL
VLL

Reputation: 10155

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 #includes.

Upvotes: 12

M.M
M.M

Reputation: 141554

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.

Upvotes: 3

Related Questions