I have the following code:
unsigned int m_font_timer = 0;
int Getsum(int p_top_left_x)
{
int l_sum = (((p_top_left_x + (m_font_timer >> 2)) & 0x7) - 4 ) >> 2;
if (l_sum < 0) l_sum = -l_sum;
return l_sum;
}
Unless I explicitly cast m_font_timer to (signed int) this part of the expression becomes unsigned:
((p_top_left_x + (m_font_timer >> 2)) & 0x7) - 4 );
Even though there is a "-4" and p_top_left_x is signed.
This is happening on a crosscompiler for SH4 using gcc 4.7.3 (I'm programming for an old system that requires it). I wasn't expecting that part to turn into unsigned. I have this code running on two other platforms also with GCC (higher version than this one) and one with MSCV and they all keep the aforementioned expression as signed.
I don't know much about compilers, is this undefined behavior? Is there any way the compiler would warn me about this? I have -Wall -Wformat=0 -Wextra -Wsign-compare but doesn't rise any warnings in that function.
Thanks!