Monthly Archives: July 2018

I Auto Know Better

Getting ready for teaching this fall and noticed the library is failing to compile for 64-bit builds with the latest version of Visual Studio 2017:

Severity Code Description Project File Line Suppression State
Warning C26451 Arithmetic overflow: Using operator '-' on a 4 byte value and then casting the result to a 8 byte value. Cast the value to the wider type before calling operator '-' to avoid overflow (io.2). xll12 c:\users\kalx\source\repos\xll12\xll\args.h 192 Active

I was baffled. Every integer is an INT32 but the compiler was still complaining. The offending line was

args[ARG::ArgumentHelp + i - 1] = argumentHelp;

When I changed this to…

auto n = ARG::ArgumentHelp + i - 1;
args[n] = argumentHelp;

…the compiler warning disappeared.

I auto know better, but I have no idea why.

Advertisements