Sunday, December 24, 2017

Volatile Variables and Restricted Pointer

A variable defined as volatile if the value of the variable may change outside the program.  For example, the variable value may be changed by hardware or by another program (multi-processing).  The compiler will reload the value from the memory every time before the variable is used.  This will disable some code optimization.

A pointer defined as restricted means the associated memory is only pointed by this pointer.  This allows the compiler to optimize code.  As there no other pointer points to the same memory area (pointer aliasing), the compiler may not save the value back to the memory immediately after it is changed.

No comments: