c++ - While loop behaving unexpectedly -


i not sure if problem compiler specific or not, i'll ask anyways. i'm using ccs (code composer studio), ide texas instruments program msp430 microcontroller.

as usual, i'm making beginner program of making led blink, located in last bit of p1out register. here's code doesn't work (i've omitted of other declarations, irrelevant):

while(1){         int i;          p1out ^= 0x01;          = 10000;         while(i != 0){             i--;         }      } 

now, here's loop work:

while(1){     int i;      p1out ^= 0x01;      = 0;     while(i < 10000){         i++;     }  } 

the 2 statements should equivalent, in first instance, led stays on , doesn't blink, while in second, works planned.

i'm thinking has optimization done compiler, have no idea may wrong.

the code being optimised away dead-code. don't want spin anyway, it's terribly wasteful on cpu cycles. want call usleep, like:

#include <unistd.h>  int microseconds = // number of 1000ths of milliseconds wait while(1){     p1out ^= 0x01;     usleep(microseconds); } 

Comments

Popular posts from this blog

jQuery Mobile app not scrolling in Firefox -

c++ - How to add Crypto++ library to Qt project -

php array slice every 2th rule -