I'm coming to the end of a large control system application that I've been working on for a couple of months, with a little niggle that I can't seem to work around.
To condense the problem to it's most bare bones form, my application contains several arrays containing text strings, for information such as fault codes and button functions, both of which are written out onto the system display. In all areas these work as per expected in the application, with one exception.
In a very specific portion of my code, where starting off or resuming a stopped/paused test program, a string of text appears in the wrong datafield on my display. One of the button function fields contains the 0 index string of the fault_strings array, which is "No Fault". At first, I thought I'd just referenced the wrong array in one of the functions, but searched the entire code to no avail. The datafield should display "No Function", and does in every one case bar this.
Most interestingly however, is this string is printing onto the screen in BLACK. Nowhere else in the application does this string EVER get printed in anything other than GREEN.
To make this line of text appear on the screen, in this color would require one of the following statements:
display_write_string("No Fault", BLACK); display_write_string(fault_strings[x], BLACK);
However, the only time this string ever get's printed, it's from the following line of code:
The function that displays the button function, is the same function called repeatedly throughout the code, whereby it updates data fields on the display marked as out of date, by whatever function caused them to be out of date.
At first, I realized that both the 0 index entry in both my fault code string array, and button function string array were actually identical, so I though the compiler must have noticed this, and was the root cause of the problem. Having made them different, the exact problem as above still arises.
I'm running through some JTAG debug work now, and will post if anything else interesting comes up, but otherwise - I'm totally lost. How can a line of code, that doesn't exist, be executed?
EDIT - I'm using -Os & -g2 optimisation and debug settings.