http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57813
Bug ID: 57813 Summary: Change of global variable ignored Product: gcc Version: 4.8.0 Status: UNCONFIRMED Severity: major Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: daniel.oertwig at gmail dot com Target: avr51 Created attachment 30450 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30450&action=edit Source code relating to the problem Hi, I assume this to be a bug in how the compiler optimizes its code. Unfortunately, I don't know enough about how the gcc works to narrow down the source of the problem. If it's me (or my code), please tell me what I am doing wrong. Basically I have a function operating on a global variable. This function calls another function which changes this global variable. But the changed value is not used by the calling function afterwards. Task * Task_getNextReady() { uint8_t priority; if (taskInfo.ready[0]) priority = 0; else if (taskInfo.ready[1]) priority = 1; else if (taskInfo.ready[2]) priority = 2; else if (taskInfo.ready[3]) priority = 3; else if (taskInfo.ready[4]) priority = 4; else if (taskInfo.ready[5]) priority = 5; else if (taskInfo.ready[6]) priority = 6; else priority = 7; // Before call to function: taskInfo.ready[priority] == &task6 // After call to function: taskInfo.ready[priority] == &task7 // Return value = 10 taskInfo.ready[priority]->wakeTime = Task_enforceTimeslice(priority); // Changed task6->wakeTime = 10 // Unchanged task7->wakeTime // Return value is &task7, which is correct. return taskInfo.ready[priority]; } I guess i could "solve" this by making the variable volatile, but I don't think that this would be "correct".