473,394 Members | 1,960 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Volatile variable

I've found this code:

void function(void) {
volatile unsigned long * pAdd, *pCntl;
........
for(i = 0, pCntl = &VICPRIORITY0, pAdd = &VICTADDR0; i < 32; ++i)
{
*pCntl++ = *pAdd++ = 0;
}
}

It's the first time that i've found volatile variable: what does it
mean?if pointers are not declared as volatile, what happens?
thanks in advance
Sep 27 '08 #1
3 2438
id*************@gmail.com wrote:
It's the first time that i've found volatile variable: what does it
mean?if pointers are not declared as volatile, what happens?
What does your text book or a scan through the recent history of this
group tell you?

--
Ian Collins.
Sep 27 '08 #2

<id*************@gmail.comwrote in message
It's the first time that i've found volatile variable: what does it
mean?if pointers are not declared as volatile, what happens?
thanks in advance
"volatile" means "may be modified/read by something outside of the program",
and thus the variable is always kept in main memory, never stored in a
register exept when actually being operated upon.
This slows down the program. So only use volatile where essential. In the
nature of things, the modifying program is outside of the competence of C.

However typically you have interrupt-driven subroutines, for instance to use
the mouse. An interrupt is generated by a mouse movement, data comes in, and
is stored in volatile x,y coordinates, and control quickly returned to the
main thread. Non-interrupt routines can then use the x,y co-ordiantes to
display the mouse cursor.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Sep 27 '08 #3
In article
<c8**********************************@e39g2000hsf. googlegroups.com>,
id*************@gmail.com wrote:
I've found this code:

void function(void) {
volatile unsigned long * pAdd, *pCntl;
.......
for(i = 0, pCntl = &VICPRIORITY0, pAdd = &VICTADDR0; i < 32; ++i)
{
*pCntl++ = *pAdd++ = 0;
}
}

It's the first time that i've found volatile variable: what does it
mean?if pointers are not declared as volatile, what happens?
thanks in advance
Actually, pAdd and pCntl are not volatile; what they points to is
volatile. Very important difference.
Sep 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Radde | last post by:
HI, Can volatile variables be accessed by many processess..or only one process can access it.. Cheers..
11
by: srinivas reddy | last post by:
Hi, Is there any chance that a program doesn' work properly even after a variable is declared as volatile? I remember somebody mentioning a scenario involving L1, L2 caches. Could anybody throw...
14
by: google-newsgroups | last post by:
Hello, even (or because?) reading the standard (ISO/IEC 9899/1999) I do not understand some issues with volatile. The background is embedded programming where data is exchanged between main...
17
by: dingoatemydonut | last post by:
The C99 standard states: "In the abstract machine, all expressions are evaluated as specified by the semantics. An actual implementation need not evaluate part of an expression if it can deduce...
22
by: Assaf | last post by:
hi all i know that i should not cross-post, but i am not sure to which group to post this question. 2 quesions about volatile: 1. i use volatile when 2 threads access the same variable...
14
by: Pierre | last post by:
Using the "volatile" keyword, creates a problem if I intend to use any of the interlocked APIs. The compiler generates an error if I use the following line, for example: ...
4
by: vijay.rajamanickam | last post by:
I am a newbie w.r.t. compiler optimizations and I believe these optimizations are generally done in function level. Can I safely assume that if I use getter & setter functions, I can effectively...
6
by: bwaichu | last post by:
Can someone help me out here? This is one of those areas of C that I am fuzzy on. I'm not quite sure when I should use volatile. If you could provide an example, that would help out a lot. I...
94
by: Samuel R. Neff | last post by:
When is it appropriate to use "volatile" keyword? The docs simply state: " The volatile modifier is usually used for a field that is accessed by multiple threads without using the lock...
10
by: S James S Stapleton | last post by:
Is volatile necessary anymore? I have a two-thread piece of code I've been testing to figure out what volatile does (fairly simple code, uses pthreads). I have an update thread (variables passed as...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.