Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Thread Closed: Off-topic

???
10/13/03 15:59
Read: times


 
#56591 - RE: harsha's points
Responding to: ???'s previous message
Hi Sriharsha,

the problem can be found at the declaration and USE of an integer.

an integer is (mostly) 16 bits wide.

your counter goes ...


258++
259++
260++
261++
etc ..


this is not what you wanted by nature.

Donald has already given a solution for your problem.

Boundary check is a common failure in coding. When declaring ANY variable. Think ALWAYS of the size.
When USING or CHECKING ANY variable, think always on boundaries.

An other sollution can be found as follow:

AT declaration
static unsigned char counter; (8 bits, no sign)



OR


AT use

counter++;
if (counter >= 256) counter = 0; (boundary)


OR (not advisable)

if ((counter&0xFF) == 255-P2)

the solution of Donald is good, but has some failure when changing code after a few months (years).

Have fun

List of 6 messages in thread
TopicAuthorDate
Un expected stalling of software            01/01/70 00:00      
   RE: Un expected stalling of software            01/01/70 00:00      
   RE: Un expected stalling of software            01/01/70 00:00      
      RE: harsha's points            01/01/70 00:00      
         RE: harsha's points            01/01/70 00:00      
         RE: harsha's points            01/01/70 00:00      

Back to Subject List