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(...) { ... }
What exactly does set_status_word() do ? If it is not using any overlayed memory (no local non-static variables, few enough parameters so they can be passed in registers), then the linker should not issue a warning. However, the lack of a warning does not mean that things can go awry. For example if the function modifies global variables. In this case, however, it is the programmers job to make sure that multiple calls of the function work correctly.
things can go awry things cannot go awry. Sorry about the typo.
unsigned int status_word; ... void set_status_word(unsigned int new_status_word) { status_word = new_status_word; }
unsigned char array_idx; unsigned char array_data[4]; void put_data_into_array(unsigned char input_data) { if(array_idx < 4) { array_data[array_idx++] = input_data; } }
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.
Christoph, Thanks for your response. Yes, set_status_word() just modifies status_word:
unsigned char xdata status_word; void set_status_word(unsigned char err, bit yes) { if (yes) status_word &= err; else status_word |= (~err & 0xF); }
0014 900000 R MOV DPTR,#err 0017 E0 MOVX A,@DPTR 0018 FF MOV R7,A ...
Obviously, this can lead to unpredictable behaviour, can't it? ... ohh yes. ;) All right, but what are the exact criteria the linker uses for deciding whether to issue or not to issue that message? Maybe the linker assumes that function arguments are passed in registers when they really aren't ? This could be a bug in the linker. Did you file a bug report ?
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? ;-)