blob: 1de9b13ab439d6484bd895dbbe4774530bf7ca9d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
<html>
<head>
<title>The VOLATILE keyword.</title>
<script language="JavaScript">
</script>
</head>
<body bgcolor="#ffffcc">
<hr>
<center><h1>The VOLATILE keyword.</h1></center>
<hr>
I have had several sugestions on how to describe volatile,
If you have any input please mail me.
<ul>
<li>The <b>volatile</b> <a href="../glossary.html#keyword">keyword</a> acts as a
<a href="../CONCEPT/data_types.html">data type</a> qualifier.
The qualifier alters the default why in which
the compiler handles the variable and does not attempt to optimize the
storage referenced by it. <i>Martin Leslie</i>
<p>
<li><b>volatile</b> means the storage is likely to change at anytime
and be changed but something outside the control of the user program.
This means that if you reference the variable,
the program should always check the physical address (ie a mapped input fifo),
and not use it in a cashed way.<i>Stephen Hunt</i>
<p>
<li>Here is an example for the usage of the volatile keyword:
<pre>
/* Base address of the data input latch */
volatile unsigned char *baseAddr;
/* read parts of output latch */
lsb = *handle->baseAddr;
middle = *handle->baseAddr;
msb = *handle->baseAddr;
</pre>
Between reads the bytes are changed in the latch.
<p>
Without the volatile, the compiler optimises this to a single assignment:
<pre>
lsb = middle = msb = *handle->baseAddr;
</pre>
<i>Tim Potter</i>
<p>
<li>A <b>volatile</b> variable is for dynamic use. E.G. for data that is to
be passed to an I/O port Here is an example.
<pre>
#define TTYPORT 0x17755U
volatile char *port17 = (char)*TTYPORT;
*port17 = 'o';
*port17 = 'N';
</pre>
Without the <b>volatile</b> modifier, the compiler would think that the
statement <code>*port17 = 'o';</code> is redundant and would remove it
from the object code. The volatile statement prevents the compiler
optimisation.<i>Alex Arzon</i>.
</ul>
<hr>
<h2>Examples:</h2>
<img src="../../GRAPHICS/computer.gif" align=left alt="o"> No example:-(
<br clear=left>
<hr>
<h2>See also:</h2>
<ul>
<li><a href="../CONCEPT/data_types.html#qualifier">const qualifier</a>
</ul>
<p>
<hr>
<p>
<center>
<table border=2 width="80%" bgcolor="ivory">
<tr align=center>
<td width="25%">
<a href="../cref.html"> Top</a>
</td><td width="25%">
<a href="../master_index.html"> Master Index</a>
</td><td width="25%">
<a href="keywords.html"> Keywords</a>
</td><td width="25%">
<a href="../FUNCTIONS/funcref.htm"> Functions</a>
</td>
</tr>
</table>
</center>
<p>
<hr>
<address>Martin Leslie
</address><p>
</body>
</html>
|