N
Noob
Hello,
I wrote the following toy program, expecting it would
NOT print anything ("expecting the unexpected").
#include <stdio.h>
int main(void)
{
int i;
unsigned char t = 250;
for (i = 0; i < 10; ++i) if (++t == 0) puts("WRAP");
return 0;
}
(On my system, CHAR_BIT = 8)
I thought that because of integral promotion rules, the value
of ++t was promoted to type int.
So t would reach 255, then the next increment would evaluate
to 256 (type int), since 256 != 0 : no output, and the value
stored back to t is 0 (256 mod 256).
What did I miss? (misunderstand)
Regards.
I wrote the following toy program, expecting it would
NOT print anything ("expecting the unexpected").
#include <stdio.h>
int main(void)
{
int i;
unsigned char t = 250;
for (i = 0; i < 10; ++i) if (++t == 0) puts("WRAP");
return 0;
}
(On my system, CHAR_BIT = 8)
I thought that because of integral promotion rules, the value
of ++t was promoted to type int.
So t would reach 255, then the next increment would evaluate
to 256 (type int), since 256 != 0 : no output, and the value
stored back to t is 0 (256 mod 256).
What did I miss? (misunderstand)
Regards.