Interactive Panel: Ask Us Anything
Why Stack Overflow recommends it
Stack Overflow users link it as the source for the panel's well-known remarks that unsigned integer types and std::size_t indices in the STL were a mistake, and that signed ints should be the default.
Recommended by 0 people across 0 different months, 2013 to 2023.
What it is
A 78-minute attendee-driven Q&A panel from a 2013 C++ conference (GoingNative), featuring Bjarne Stroustrup, Andrei Alexandrescu, Herb Sutter, Scott Meyers, Chandler Carruth, Sean Parent, Michael Wong and Stephan T. Lavavej. Speakers answer open questions on C++ design and practice.
What people said
Cites 6502 · 2013-01 · Stack Overflow · on “Iterator Loop vs index loop”
With a vector iterators do no offer any real advantage. The syntax is uglier, longer to type and harder to read. Iterating over a vector using iterators is not faster and is not safer (actually if the vector is possibly resized during the iteration using iterators will put you in big troubles). The idea of having a generic loop that works when you will change later the container type is also mostly nonsense in real cases. Unfortunately the dark side of a strictly typed language without serious typing inference (a bit better now with C++11, however) is that you need to say what is the type of everything at each step. If you change your mind later you will still need to go around and change ev
Cites edmz · 2014-09 · Stack Overflow · on “C vs C++ file handling”
@TonyD I could find the video [this video] and basically he was referring to formatting: you don't have to repeat it.
Cites InsideLoop · 2015-02 · Stack Overflow · on “Does max_size() of std::vector<char> have a bug?”
Bogdan: Bjarne Stroustrup, Herb Sutter and Chandler Carruth recognized the mistake of using std::size_t in the STL. As they say "We were young...". It's here [this video] , at 42:38 and 1:02:50 .
Cites Destructor · 2015-05 · Stack Overflow · on “Why are unsigned integers error prone?”
I was looking at this video [this video] . Bjarne Stroustrup [LINK] says that unsigned ints are error prone and lead to bugs. So, you should only use them when you really need them. I've also read in one of the question on Stack Overflow (but I don't remember which one) that using unsigned ints can lead to security bugs. How do they lead to security bugs? Can someone clearly explain it by giving an suitable example?
Cites Jon · 2015-07 · Stack Overflow · on “Why is size_t unsigned?”
A relevant quote from Herb Sutter [this video] : "Use int unless you need something different, then still use something signed until you really need something different, then resort to unsigned. And yes, it's unfortunately a mistake in the STL and the standard library that we use unsigned indices."
Cites Arne · 2015-11 · Stack Overflow · on “When to use std::size_t?”
short answer: Almost never . Use signed version ptrdiff_t or non-standard ssize_t . Use function std::ssize instead of std::size . long answer: Whenever you need to have a vector of char bigger that 2gb on a 32 bit system. In every other use case, using a signed type is much safer than using an unsigned type. example: std::vector<A> data; [...] // calculate the index that should be used; size_t i = calc_index(param1, param2); // doing calculations close to the underflow of an integer is already dangerous // do some bounds checking if( i - 1 < 0 ) { // always false, because 0-1 on unsigned creates an underflow return LEFT_BORDER; } else if( i >= data.size() - 1 ) { // if i already had an unde
Cites InsideLoop · 2018-02 · Stack Overflow · on “Is there still a reason to use `int` in C++ code?”
Many style guides such as the Google one recommend using int as a default integer when indexing arrays for instance. With the rise of 64-bit platforms where most of the time an int is only 32 bits which is not the natural width of the platform. As a consequence, I see no reason, apart from the simple same, to keep that choice. We clearly see that where compiling the following code: double get(const double* p, int k) { return p[k]; } which gets compiled into movslq %esi, %rsi vmovsd (%rdi,%rsi,8), %xmm0 ret where the first instruction promotes the 32 bits integer into a 64 bits integer. If the code is transformed into double get(const double* p, std::ptrdiff_t k) { return p[k]; } the generate
Cites geza · 2019-05 · Stack Overflow · on “Why is std::ssize() introduced in C++20?”
@L.F.: I've found Herb's mentioning this: [this video] When he says that "does not come up in practice very much", it is true nowadays. But it wasn't true >20 years ago (16-bit systems) at all. So, it was not that much of a mistake to use unsigned, when the STL was designed.
Cites VoiceOfUnreason · 2023-09 · Stack Overflow · on “Unsigned number instead of checking invariant in DDD”
If you know a number cannot be negative, which design is better in a DDD model ? I can't think of a single DDD example I have seen that uses unsigned types as a general purpose data structure. The general rule for unsigned types is that you use default to using a signed type, and use unsigned types only when appropriate to the specific task at hand. Google C++ Style Guide [LINK] Do not use an unsigned type merely to assert that a variable is non-negative. CPP Core Guidelines: ES106 [LINK] Don't try to avoid negative values by using unsigned Stroustrup, Sutter and Carruth were of unanimous opinion in 2013 Video [this video] Transcript [LINK] courtesy of Nayuki (near bottom of page) Online discussi