Technical Support

GENERAL: DISABLING THE OPTIMIZER (FOR VOLATILE VARIABLES)

QUESTION

Is there any way to totally disable optimizing? I need to do 2 consecutive reads of an external unsigned byte pointer. Instead of reading it the second time, the compiler just gives me the value from the first read. I tried setting optimizer to zero, but it didn't change.

ANSWER

Multiple accesses to the same external variable may require that the variable is declared as volatile. This will force the compiler to access the variable the second time. Variables are declared this way as follows:

volatile unsigned char variable;

For more information, refer to the volatile keyword in Kernighan & Ritchie's "The C Programming Language". Also, refer to the ABSACC.H header file in the \C51\INC directory for an example of absolute memory access macros.

Last Reviewed: Wednesday, November 07, 2001


Did this article provide the answer you needed?
 
Yes
No
Not Sure