View previous topic :: View next topic |
Author |
Message |
khannic
Joined: 09 Dec 2008 Posts: 4
|
for(j=7; j>-1; j-=2) cause infinite loop |
Posted: Sun Feb 01, 2009 1:54 pm |
|
|
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
|
|
Posted: Sun Feb 01, 2009 2:13 pm |
|
|
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:
|
|
|
khannic
Joined: 09 Dec 2008 Posts: 4
|
|
Posted: Sun Feb 01, 2009 2:24 pm |
|
|
that's works thx for very rapid reply |
|
|
|