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 CCS Technical Support

Compiler 3.222 Cant run Program from Ver 3.219

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



Joined: 25 Oct 2004
Posts: 136

View user's profile Send private message

Compiler 3.222 Cant run Program from Ver 3.219
PostPosted: Thu Mar 17, 2005 9:44 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Mar 17, 2005 9:52 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Thu Mar 17, 2005 9:52 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Mar 17, 2005 10:18 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Thu Mar 17, 2005 10:22 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Mar 17, 2005 2:23 pm     Reply with quote

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







PostPosted: Thu Mar 17, 2005 4:35 pm     Reply with quote

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
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