- Which CPU are you targeting: MCF52258
- Which version of CodeWarrior are you using? 10.0 and 10.1 (we see problem on both)
Hi! We are seeing some unexpected global variable behavior:
In one file the code writes a value into an element of a global structure, but when the code reads the same value in another file it isn't what was written. This is because it's reading (the same structure element) from a different memory location. For example: When the variable 'tva.options.probe_type' is accessed in the probe.c function 'probe_init()' - the address shown by the debugger is 0x20004f69; the address shown in the assembly code window, and what is changed in the memory is 0x20004eb4. This means the function 'probe_init()’ accesses and changes the wrong variable.
Does anyone have any ideas on how we can get to the bottom of this behavior?
One of my colleagues found a setting in the project properties that appears to have fixed the issue:
Properties --> C/C++ Build --> Settings --> Coldfire Compiler --> Processor --> set the "Struct align" setting to "byte".
This got all the modules to look at the same addressing for the global variable structure, as far as we can tell. It did take care of the instances we were aware of, anyway.
Thanks to those of you who posted suggestions!
Dear Eric,
It's a bit hard to respond without an example of the code. Can you do a simple test case demonstrating the problem?
One question - Is it the entire structure that is at multiple addresses or is it that it is treating the fields at different offsets within the structure?
Some things to check:
bye
Declaring it static can also help.