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 support@ccsinfo.com

"volatile" not really used in CCS compiler?

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







"volatile" not really used in CCS compiler?
PostPosted: Fri Sep 10, 2004 4:40 am     Reply with quote

Hi,

The way I understood 'volatile' to be used is to inhibit compiler optimization. Thus a global variable in an ISR should have a volatile if it is to be used in other functions.

I have found that I do not have to designate any variables as 'volatile', and things still work fine.

What then would be the use of "volatile" in the CCS compiler?
Trampas



Joined: 04 Sep 2004
Posts: 89
Location: NC

View user's profile Send private message MSN Messenger

PostPosted: Fri Sep 10, 2004 5:47 am     Reply with quote

Volatile is used to say that this variable may be changed by something that is not apparent in the code running at the moment.

For example lets say I have an ISR routine and I have a global variable...

[code]
UINT done=0;

void isr()
{
done=1;
}


void main()
{

while(!done)
{
}
}
[/done]

In this case the compiler with out knowing that done is set by another thread/process it may look and say well done is not set in the main, but initially set to zero. Then it is not modified in the while loop either. Therefore the compile may optimize the code to be while(1).

Thus any time a variable may change outside of the code you are running it should be a volitale. For example, all peripheral registers should be voltile as they may change outside of code. All hand shaking signals in ISR routines should be volatile as well, like the done above.

Trampas
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

PostPosted: Fri Sep 10, 2004 5:55 am     Reply with quote

Unless CCS made changes recently, volatile can be used when declaring a variable but the compiler just ignores it!
valemike
Guest







PostPosted: Fri Sep 10, 2004 6:53 am     Reply with quote

I agree with Trampas' explanation. However, like I said in the first post, that even if i don't use volatile for a global var used in an isr, it still works just fine, as if the compiler does no optimization of it whatsoever with or without the volatile keyword specified.

So it is like Mark's observance. Volatile is just ignored, and I would go further to assume that you can imply all variables are inherently volatile.
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Fri Sep 10, 2004 6:53 am     Reply with quote

I think CCS considers everyting to be volitile. The only place where it matters is when a variable is stored in external memory where it could be modified by another processor that this compiler does not know about, but that has access to the same external memory. Rather than fetching the variable to RAM and using it several times a volitile variable should be fetched to RAM from external memory each time it is used.
_________________
The search for better is endless. Instead simply find very good and get the job done.
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