This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Use of Extern for sharing veriables

I have a basic question regarding definition and declaration of variables and use of the extern attribute.
I thought I understood it but may be not.
Here is what I have. 3 separate files.. One of the shared variable works (Pkt), the other (LLC) does not.

I would appreciate if anyone can explain this and more important, clearly specify what needs to be done... (A headers.h file calls out subroutines such as rtn1.c so that they do link ok.)

//externals.h file
extern unsigned char xdata Pkt[10];
extern unsigned char xdata LLC;
extern unsigned char *k;
...
//Main.c file... variables are defined here.
unsigned char xdata Pkt[10];
unsigned char xdata LLC;
unsigned char *k;
...
void main (void) {
...
Pkt[0] = 0x01;
LLC = 0x02;
...
}
//subroutines.c file
#include <externals.h>
..
void rtn1 (void){
..
k= &Pkt[0]; // <--- No errors
..
k=&LLC; // <--- Compiler says error (C202): 'LLC': undefined identifier LLC .... WHY ???
..
}

0