Is it guaranteed that this piece of code print always values from 0 to 15 on any platform?
#include <stdio.h>
typedef struct UI4{
unsigned value: 4;
} ui4;
int main(void)
{
ui4 u;
u.value = 0;
while (1) {
printf("%u\n", u.value++);
}
return 0;
}
Yes, unsigned integer overflows are guaranteed to “wrap around” by the standard.