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

for(j=7; j>-1; j-=2) cause infinite loop

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



Joined: 09 Dec 2008
Posts: 4

View user's profile Send private message

for(j=7; j>-1; j-=2) cause infinite loop
PostPosted: Sun Feb 01, 2009 1:54 pm     Reply with quote

Code:
int j;

for(j=7; j>-1; j-=2){
   printf("%d ", j);
}


The result is 7 5 3 1 -1 -3 -5.... and loop is never end. What happened ?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Feb 01, 2009 2:13 pm     Reply with quote

In CCS, an 'int' is an unsigned 8-bit integer. All CCS integer data types
are unsigned by default (different from the C standard).

Download the CCS manual:
http://www.ccsinfo.com/downloads/ccs_c_manual.pdf
Look at this table, on page 49 in the Acrobat Reader:
Quote:
Basic and Special types

On page 50 (in Acrobat reader), it says this:
Quote:
Note: All types, except float, by default are unsigned;


To get a signed variable, you need to declare it like this:
Code:
signed int j;
khannic



Joined: 09 Dec 2008
Posts: 4

View user's profile Send private message

PostPosted: Sun Feb 01, 2009 2:24 pm     Reply with quote

that's works thx for very rapid reply Surprised
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