What happens when I have an integer variable and use it in a for loop that requires a long integer variable?
What would happen to the "t" variable in the code below? it will increment to 255 (since t is declared as integer) and then what? would it be reset to zero, if so, the loop will never exit right?
Code:
// Test
int t = 0;
fprintf(PC,"Begin Bad Counter...\r\n");
for (t = 1; t <= 1200; t++) delay_ms(50);
fprintf(PC,"End Bad Counter...\r\n");
Thank you in advance
Peter
coolio Guest
Posted: Wed Jan 25, 2006 3:18 pm
If you increment an unsigned 8-bit value past 255 you will end up at zero. For signed values you will hit -128 once you increment past 127.
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
Posted: Thu Jan 26, 2006 8:37 am
It will loop forever because t <= 1200 will always be true. _________________ The search for better is endless. Instead simply find very good and get the job done.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum