lefticus / cpp_weekly

The official C++ Weekly Repository. Code samples and notes of future / past episodes will land here at various times. PR's will be accepted in some cases.
The Unlicense
663 stars 24 forks source link

Integer conversion best practices. #379

Open bleppard opened 2 months ago

bleppard commented 2 months ago

Channel

"C++Weekly" episode request

Topics

Ok, auto conversion between integer types is evil. Got it. We need to get our tools to help us find silent conversions. Got that. So when you absolutely have to do a narrowing or signed conversion (size_t to int, or int64_t to int32_t, what are some best practices? gsl::narrow boost::numeric_cast static_cast have faith that we will dodge overflow, underflow, and sign extension bugs something else

Our code base has accumulated examples of all of these. Yuk.

Length

bite-sized (5-10 minutes)?