View previous topic :: View next topic |
Author |
Message |
Andreas
Joined: 25 Oct 2004 Posts: 136
|
Compiler 3.222 Cant run Program from Ver 3.219 |
Posted: Thu Mar 17, 2005 9:44 am |
|
|
Hi Friends,
I have a quit nasty Problem with the Compiler 3.219 so I decided
to change to Version 3.222 and now I have much bigger troubles.
The program which is well tested with 3.219 and runs perfect is
now with the new version just starting runs a few milliseconds and then
resets to zero and execution stops !!!!
The problem I had is the following:
The initial values are:
testcalc = 3000
RAMBuffer1[3] = 52
CODE Begin
testcalc = RAMBuffer1[3] - 0x30;
RPage = RPage + testcalc + 100;
CODE End
This will give me a correct Result !
Result : RPAGE = 3400
But using this:
CODE Begin
RPage = Rpage + ((RAMBuffer1[3] - 0x30) + 100);
CODE End
Result : RPAGE = 3144
This is wrong !!
I hope somebody out there can help me !
Whatsgoing wrong with new version ???
best regards
Andreas |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Mar 17, 2005 9:52 am |
|
|
If you want us to test it, you need to post a complete test program,
with the #include statement for the PIC, and variable declarations
so we can see the data types that you're using. Also show the
#fuses statement, etc. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Thu Mar 17, 2005 9:52 am |
|
|
3000 + (52-0x30) + 100 = 3104 so none of the values you gave are correct. Please post a small but working program that demonstrates the problem. This eliminates all the guess work. |
|
|
Andreas
Joined: 25 Oct 2004 Posts: 136
|
|
Posted: Thu Mar 17, 2005 10:18 am |
|
|
Hi ,
Sorry but the whole Code is very large allready so I just made a snippnet.
The follwoing line had a misstake:
RPage = RPAGE + testcalc * 100; Result is correct 3400 decimal !
Also this line had the same misstake:
RPage = RPAGE +((RAMBuffer1[3] - 0x30) * 100); this gives the wrong result 3144 !
Thanks both of You to reply so fast and sorry for the misstake !
Processor used : 18F8720
declare for testcalc: int16
declare for RPAge: int16
declare for RAMBuffer1[1056] : int8 ; Is the Receive Input Buffer
best regards
Andreas |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Thu Mar 17, 2005 10:22 am |
|
|
Casting problem. 4*100 = 400 but since RAMBuffer1[3] is 8 bit then 400 or 0x190 becomes 0x90 or 144. You will need to case RAMBuffer1 to an int16. |
|
|
Andreas
Joined: 25 Oct 2004 Posts: 136
|
|
Posted: Thu Mar 17, 2005 2:23 pm |
|
|
Hi Mark,
Thank for Your reply, sounds to me very logical now !
The main reason why I was so uncertain is , that one line above I made this
Statement:
RPage = ((RAMBuffer1[2]) * 1000);
And this worked fine !
So am I right that there is a difference in the behavior of C depending on
the syntax ?
This line : RPage = RPage + ((RAMBuffer1[2]) * 1000); would not work ?
Thanks again for Your answer
best regards
Andreas |
|
|
Ttelmah Guest
|
|
Posted: Thu Mar 17, 2005 4:35 pm |
|
|
Not really.
The reason the latter example gave the expected result, is that '1000', is automatically a long, since it won't fit in a normal integer. The compiler will always use the 'highest' type involved when dealing with a pair of numbers, to determine the arithmetic to use. If you used:
RPage = ((RAMBuffer1[2]) * 100L);
Note the added 'L', this too would work as you expect, since it forces the constant to be treated as a 'long', and again forces the higher type to be used. If you look through some of my past posts about type casting, I have suggested that whenever you want to force this behaviour, using the 'L' marker is a good way of ensuring the required behaviour.
Best Wishes |
|
|
|