Optimizes the access to the elements of an array.
#pragma safe_index_expr on | off | reset
off
It is applicable to the optimization level O3.
The compiler uses this pragma to decide whether it can optimize access to several elements of the same array in expressions such as, some_array[i] + some_array[i + <offset>].
Optimization is safe and performed only if this pragma is on. Only enable this pragma if the index expression cannot produce an overflow with respect to its type.
The following listing displays an example of correct pragma usage:
unsigned int index = 0xF; char value; #pragma safe_index_expr on void func(char *array) { value = array[index] + array[index + 2]; /* 'index + 2' does not overflow wrt 'unsigned int' */ } void main(void) { char array[] = {0, 1, 2, 3, 4, 5}; func(array); }
The following listing shows an example of incorrect pragma usage:
unsigned int index = 0xFFFF; char value; #pragma safe_index_expr on void func(char *array) { value = array[index] + array[index + 2]; /* '0xFFFF + 2' overflows wrt 'unsigned int' */ } void main(void) { char array[] = {0, 1, 2, 3, 4, 5}; func(array); }