Today, Vikram Ojha asked via email:
I was just thinking why we removed “int” as default return type from C++ which was there in our traditional C type. Why we made such changes, is it to make language more safer?
Short answer: Because it’s ‘inherently dangerous’ in the words of the C committee.
For C++, see D&E (The Design and Evolution of C++) index “implicit int” which takes you to section 2.8.1. For C, see the C99 Rationale section 6.7.2 — interestingly, you can’t search for “implicit int” because that term isn’t used — this is where the string to search for is “inherent danger” :).
Cribbing from Bjarne’s writeup, “implicit int” was removed some 20 years ago for several reasons, including code clarity and in additional avoiding special cases, to simplify C++ code and/or the C++ grammar.
For example, what does this mean?
void f(const T);
In modern C++, it can mean only that f has a const parameter of type T that is unnamed.
If we had implicit int, this would be less obvious: Could it also be a const parameter of type int named T?
There are a number of other cases where just omitting the type, with the meaning that it’s a certain fixed type, makes the grammar and/or the program harder to think about than it should be. So the ability to do that was removed in both C and C++.
While we were both at CppCon last month and had cameras around, Brian Overland interviewed me for InformIT. The video just went up a couple of days ago.
Mark Maimone of NASA and Mars Rover fame.
Bjarne taking questions after his talk.
“We’re sold out of A Tour of C++ again… how about this instead?” [photo credit: Artur Laksberg]
[photo credit: Artur Laksberg]
[photo credit: Artur Laksberg]
Walter Brown speaking in one of the six concurrent breakout sessions.
Jon Kalb speaking in one of the other rooms.
Possibly the youngest attendee? [photo credit: Artur Laksberg]
Accessibility and community.
Yup. Modern C++.
View from the CppCon balcony before diving into more evening sessions.
So long, Meydenbauer Center… see you next year! [photo credit: Hyrum Wright]