I need some clarification about using structure and externs. My code is like this.
cfile.c
volatile struct my_struct{
char *buf;
int size;
int read;
int write;
}rx,tx;
void foo1()
{
rx.size = 256;
rx.buf = (char *)malloc(rx.size * sizeof(char));
rx.read = 0;
rx.write = 0;
tx.size = 256;
tx.buf = (char *)malloc(tx.size * sizeof(char));
tx.read = 0;
tx.write = 0;
}
xyzFile.c
//extern the structure
Use structure variable in this function
void foo2(void)
{
int next;
next = (rx.write + 1)%rx.size;
rx.buf[rx.write] = data;
if (next != rx.read)
rx.write = next;
}
In this function foo i'm getting this data rx.buf
and wanted to use this data in cfile.c
. How can i do that?
Thanks in advance.