我的代码非常适合从链表的值填充数组而无需优化。一旦我启用优化 (-02) 数组中的第一个值正确加载,但所有后续值显示不正确(无效的内存范围)。
typedef struct lineInfo_s lineInfo_t;
struct lineInfo_s{
unsigned short * lineBuffer;
volatile lineInfo_t * next;
volatile lineInfo_t * prev;
};
static unsigned char blankLine[72]; //Use this when no entry in linked list
static void foo(lineInfo_t * lineAddr) {
unsigned char * lines[6];
bool noNext = lineAddr->next==0UL;
bool noNextNext = true;
if(!noNext) noNextNext = (lineAddr->next)->next==0UL;
...
//Load the Array
lines[0] = (unsigned char*)lineAddr->lineBuffer;
lines[1] = (noNext)? blankLine:(unsigned char*)(lineAddr->next->lineBuffer);
lines[2] = ((noNext||noNextNext)? blankLine:(unsigned char*)(lineAddr->next)->next->lineBuffer);
lines[3] = (lineAddr->prev==0UL)? blankLine:(unsigned char*)(lineAddr->prev->lineBuffer);
//Print results
printf("%08X %08X %08X %08X", lines[0], lines[1], lines[2], lines[3]);
...
}
关于为什么这不能正确优化的任何明显信息?