View previous topic :: View next topic |
Author |
Message |
Keith Ward Guest
|
Correct Behavior of long int (int16)? |
Posted: Tue Apr 01, 2003 8:46 am |
|
|
I am using an older version of the PCM compiler (2.674) but the newer ones may function the same way. When defining a long and then assigning various values the long appears to work correctly but when attempting to increment a long (e.g. count++) only the lower byte gets updated and it functions as though it were just an int (int8). Is this a bug or a feature?!
___________________________
This message was ported from CCS's old forum
Original Post ID: 13284 |
|
|
Steve H. Guest
|
2.685 Works Correctly |
Posted: Tue Apr 01, 2003 9:02 am |
|
|
___________________________
This message was ported from CCS's old forum
Original Post ID: 13286 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: Correct Behavior of long int (int16)? |
Posted: Tue Apr 01, 2003 12:48 pm |
|
|
:=I am using an older version of the PCM compiler (2.674) but the newer ones may function the same way. When defining a long and then assigning various values the long appears to work correctly but when attempting to increment a long (e.g. count++) only the lower byte gets updated and it functions as though it were just an int (int8). Is this a bug or a feature?!
-----------------------------------------------------------
I installed PCM vs. 2.674 and it works OK for me.
The following sample program has this output:
12fe
12ff
1300
1301
<PRE>
#include "c:\picc\test\16F877.H"
#fuses HS, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
#use Delay(clock=8000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
<BR>
//====================================================
void main()
{
long k;
<BR>
<BR>
k = 0x12FE;
printf("\%lx\n\r", k);
k++;
printf("\%lx\n\r", k);
k++;
printf("\%lx\n\r", k);
k++;
printf("\%lx\n\r", k);
<BR>
<BR>
while(1);
}
</PRE>
___________________________
This message was ported from CCS's old forum
Original Post ID: 13290 |
|
|
Jerry Finsen Guest
|
Re: Correct Behavior of long int (int16)? |
Posted: Tue Apr 01, 2003 3:52 pm |
|
|
I have recently reported a related problem. I have a program that has a statement in the form:
X += Y * Z that does not work, while the form X = X + (Y * Z) does work. All variables unsigned int16. Errors on the first form appear after 255 is reached. Below that all is OK. The errors are not consistant at 255, sometimes 260-280 -- I really don't understand that.
___________________________
This message was ported from CCS's old forum
Original Post ID: 13293 |
|
|
Keith Ward Guest
|
Re: Correct Behavior of long int (int16)? |
Posted: Tue Apr 01, 2003 8:04 pm |
|
|
Ok, here it is. As much as I hate to admit it the sanity checks from all of your responses told me it was not a bug. The problem was that I'm using a 16C84 and not a 16F84 ... that alone fixed it!
I hate it when this sort of thing creeps in. It really keeps you from the "real" project. I really should learn when I'm too tired to work on things and just go to bed!
:=I am using an older version of the PCM compiler (2.674) but the newer ones may function the same way. When defining a long and then assigning various values the long appears to work correctly but when attempting to increment a long (e.g. count++) only the lower byte gets updated and it functions as though it were just an int (int8). Is this a bug or a feature?!
___________________________
This message was ported from CCS's old forum
Original Post ID: 13299 |
|
|
|