| ||||||||
Technical Support Support Resources Product Information | C51: OPTIMIZER LEVELS AND VOLATILE VARIABLESQUESTIONHelp. We are porting code from an ancient C compiler to C51 Version 5.1 and we have a lot of memory-mapped devices. We access them using variables that are located at the physical address of the device. However, when the code was originally ported, the volatile keyword was left out. We are having problems because of code fragments like the following: ADC_REG = 0x80; ADC_REG = 0x01; ADC_REG = 0x0A; In these types of situations, the compiler optimizes out the first two assignments (which are critical). We are working on getting these variables declared with volatile, but, is there a different optimizer level we can use in the meantime to avoid this problem? ANSWERYes. To figure out the optimizer level to use, we wrote the following "program":
void main (void)
{
volatile int i;
int j;
i = 1;
i = 2;
i = 3;
j = 1;
j = 2;
j = 3;
}
After compiling with all optimizer levels, optimizer level 3 is the setting that preserves all assignments. This is the optimizer level to use. NOTE: This optimizer level may include new or improved optimization techniques. It is best to run this simple example to see what optimizer level will work for you. Last Reviewed: Thursday, May 20, 2004 | |||||||
| ||||||||