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

"Volatile" is it possible to use the keyword in CC

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








"Volatile" is it possible to use the keyword in CC
PostPosted: Sun Mar 22, 2009 9:32 am     Reply with quote

Hi all,

I have a query related to CCS C optimisation.
Does it support "volatile" key word.

I have a chuck of code as follows
Code:
  tmRPS = RPS;
 
   handleKeypad();//may change the value of RPS by user  from keypad

   if(tmpRPS != RPS)
   {
      //perform controll action
      //Control loop
   }

the memory being alocated for both RPS and tmpRPS is different , RPS is global variable , and tmpRPS is local variable.
if the value of RPS is changed within the function handleKeypad() then the value of tmpRPS automaticaly changes to the new value of RPS. Thus the program execution never enters the control loop as both are always equal.
I tried making both RPS,tmpRPS as volatile int32 variables but it dose not work.

Is there any way out to prevent the compiler to do such an optimisation.
My set optimisation level is 0. I have done it through the MPLAB Ide options.
Or is it require to specificaly use #opt option in the code.

I have one more question,

in a particular function i have a for loop counting up to 3
inside this for loop i have a permenent while loop scanning for a particular key press. when i detect a key press i increment a particular variable and break from the while loop by using the key word "break;".
It is expected that the for loop is executed for 2 more times, but some how after the "break" is executed for the first time the for loop is also exited. whihc is quite strange. Can any body help me out os these strange issues.

Thanks and regards
Rohit
dyeatman



Joined: 06 Sep 2003
Posts: 1939
Location: Norman, OK

View user's profile Send private message

PostPosted: Sun Mar 22, 2009 10:10 am     Reply with quote

What version are you using? The memory allocation problem sounds like one CCS had back in version 3. How about providing some code we can drop in and test?
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

Re: "Volatile" is it possible to use the keyword i
PostPosted: Sun Mar 22, 2009 10:17 am     Reply with quote

Anonymous wrote:
Hi all,

I have a query related to CCS C optimisation.
Does it support "volatile" key word.

I have a chuck of code as follows

tmRPS = RPS;

handleKeypad();//may change the value of RPS by user from keypad

if(tmpRPS != RPS)
{
//perform controll action
//Control loop
}

the memory being alocated for both RPS and tmpRPS is different , RPS is global variable , and tmpRPS is local variable.
if the value of RPS is changed within the function handleKeypad() then the value of tmpRPS automaticaly changes to the new value of RPS. Thus the program execution never enters the control loop as both are always equal.
I tried making both RPS,tmpRPS as volatile int32 variables but it dose not work.

I don't think the problem is what you think it is. Take a look at the generated .LST file to see for sure what the compiler is doing with your "if" statement.
Quote:

in a particular function i have a for loop counting up to 3
inside this for loop i have a permenent while loop scanning for a particular key press. when i detect a key press i increment a particular variable and break from the while loop by using the key word "break;".
It is expected that the for loop is executed for 2 more times, but some how after the "break" is executed for the first time the for loop is also exited..

A break executed in the inner "while" loop will only take you out of that "while" loop. It will not force an exit from the "for" loop, unless you did something in the "while" loop that changes the variable being used in the "for" loop.
_________________
Robert Scott
Real-Time Specialties
Embedded Systems Consulting
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