>>>>> "Stephane" == Stephane Bouchard <[EMAIL PROTECTED]> writes:

 Stephane> 2- What is the key word "volatile" in C? It's not wrote in
 Stephane> my C book.

You must be looking at K&R, which is very old.  Get an ANSI C book
(Harbison & Steele, "C, a reference manual" is a nice one).

"volatile" means that the data being referenced can change without
action from the program.  It tells the compiler that every read and
every store expressed in the program must actually appear in the
binary, and in the order shown.

For example:
        int *p;
        volatile int *q;

        *p = 1; *p = 2;
        *q = 3; *q = 4;

The compiler is allowed to get rid of the "*p = 1" since the statement 
after it overwrites the result.  But since q is a pointer to volatile
int, it is not allowed to get rid of the "*q = 3" so it will always do 
two stores, and they will go in the order shown.  You need "volatile"
when referencing to I/O device registers and things like that -- spots 
in "memory" where accesses have side effects and contents change
spontaneously.

        paul
--- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
----
For more information on Real-Time Linux see:
http://www.rtlinux.org/~rtlinux/

Reply via email to