If I write the code like this:
auto n = 2048 * 2048 * 5;
char* buf = new char[n];
So, Is auto deduction type safe from the integer overflow in C++17?
If I write the code like this:
auto n = 2048 * 2048 * 5;
char* buf = new char[n];
So, Is auto deduction type safe from the integer overflow in C++17?
Copyright © 2021 Jogjafile Inc.
2048and5in C++ have a type, and that type isint. Multiplying twoint's has a type and that type isint. There are values for which the result cannot fit in anint, andautocannot prevent that.What
autocan prevent is accidentally narrowing the result, e.g.: