I am programing with TDD, where all warnings are converted to errors, and I am having a strange warning/error. I have a code like this
short int a = 0;
/* .... */
a = a + 2;
when I compile, I get this message
error: conversion to 'short int' from 'int' may alter its value [-Werror=conversion]
but if I change this line:
a = (short int)(a + 2);
the error dissapear. My question is, is really necessary to cast ALL my increments/decrements, or any basic operation? Why, in a operation where all the variables or constants are short int, the compiler is casting something to int? Even if I change the line to
a = a + (short int)1;
the error appears, so I think the problem is not the constant
I use
g++ (Debian 6.3.0-18+deb9u1) 6.3.0 20170516