use of volatile ?

  • Thread starter parasprajapati2001
  • Start date
D

David Thompson

You should try compiling any code before you post it here.
<snip corrections to types>

But the compiler doesn't catch everything. Even with required
diagnostics corrected the example doesn't work as intended.

In order to 'ensure' -- in scarequotes because the implementation is
allowed to weasel out of really doing volatile, but at least as far as
the generally accepted _intent_ -- that the "I/O port" is in fact read
twice, not just read once and reused, what you need is:
/* here */ volatile char * ioport = suitable_initialization;
/* not here */ char ch = * ioport; /* etc. */

or if you prefer
char * ioport = whatever;
char ch = * (volatile char *) ioport;

And this is leaving aside that plain char may be signed at the
implementation's option, so you very likely want unsigned char.

- formerly david.thompson1 || achar(64) || worldnet.att.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

The Semantics of 'volatile' 73
Qsort() messing with my entire Code 0
Proper Use of Volatile? 6
volatile Info 56
volatile 4
Volatile and code reordering 1
volatile and multiple threads 10
Volatile? 3

Members online

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top