Please consider the following code.
//--- module main.c --- ... void main() { ... set_status_word(...); ... } //--- module can.c --- ... void CAN_int_handler(void) interrupt 7 { ... set_status_word(...); ... } //--- module utils.c --- ... void set_status_word(...) { ... }
The function is intrinsically reentrant. *sigh* Ok, I wrote this too fast. This function can still result in a garbled value of status_word, because each of the two bytes is written individually. If there's an interrupt (with another call of set_status_word()) right after the first byte is written, status_word might get set to an erroneous value.
This forum doesn't seem to add new messages at the end... Never mind. This could be a bug in the linker. Did you file a bug report ? Not yet. First, I want to make sure it isn't my bug. Besides, it would be a second bug I found in Keil C. Too many for a single programmer, isn't it? ;-)