No warnings on the loop counter

I find it hard to understand why the following code does not warn:

unsigned test = 0xffffffff;

for (unsigned char i = 0; i < test; i++)
{
    // Some code
}

This is on Visual Studio 2010, but GCC obviously does not warn you either. Does anyone know why?

+5
source share
4 answers

From a linguistic point of view, this is nothing. irises unsigned intto a grade <. And it is perfectly defined to increase unsigned charso that it wraps to zero.

The fact that this code is causing something annoying is unsuccessful. But it’s not clear which rule the compiler needs to apply to discover these kinds of things.

@unwind : GCC , true, -Wtype-limits.

2: -, ( "" GCC ...)

+6

i unsigned, test. . . ++ char, . , 255 0, , , potencialy , (, ..). "" " .

+1

unsigned char unsigned . - , , - .

+1

:

4.5

, bool, char16_t, char32_t wchar_t, (4.13) int int, int ; prvalue prvalue unsigned int.

+1

All Articles