CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

While compares in MPLAB

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
collison
Guest







While compares in MPLAB
PostPosted: Tue Dec 20, 2005 3:20 pm     Reply with quote

I am having trouble with a while loop. The code is as follows:

while(j>x)
{
}

For some reason it does not like comparing two variables in this manner. It works if I put a number in the place of one of the variables, but it won't execute with two variables in place. Any ideas on why this is and what I can do to fix it????

Thanks
Ttelmah
Guest







PostPosted: Tue Dec 20, 2005 3:29 pm     Reply with quote

It should work fine.
The commonest problem, is with forgetting the 'size limits' on variables (remember that if these are only integers, 255 is the largest value, and if 'signed', 127). Test the comparison, by generating an expression, and verify that it would return non zero (true), when you expect. Another 'classic', is with an unsigned variable, that can (of course), never be -ve. The handling of overflows is non-existent/poor in CCS, so you must ensure that your variables can cope in all cases. I have used such expressions in hundreds of places without problems.

Best Wishes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 20, 2005 3:30 pm     Reply with quote

Make a complete (but small) test program that shows the problem.
Show all #include, #fuses, and #use statements. Show all variable
declarations. Initialize the variables to some value. Put something
inside the while loop to show that it's running (such as a printf statement).
Then test it and post it.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group