pointers - C in PIC32, Passing a Struct Variable between 2 *.c File -
i have hit wall , speed.
i have "filea.c" file , "fileb.c" file pass variables between. furthermore, "filea.h" , "fileb.h" headers respectively.
a variable uint16 storage1.cntlog1.posedge
in "filea.c" "fileb.c". how do using pointer?
below code snippet of filea.h header file , pass fileb.c variable posedge reference. there 2 varibales posedge 1 in header , other in c file. do.
typedef struct { uint16 posedge; } s_posedge; typedef struct s_cntlog1 { s_posedge cntlog1; } s_cntlog1;
this snippet of filea.c
typedef struct { uint16 posedge; } s_cntlog2; private s_cntlog1 storage1; private s_cntlog2 *storage2 = null; storage1.cntlog1.posedge = storage2->posedge;
what tried........ tried using
uint16 sharelog(void) { return (storage1.cntlog1.posedge); }
and declaring in header "filea.h", "#include filea.h" in "fileb.c" , furthermore blink led if (storage1.cntlog1.posedge==0x01)
i have no idea how can send information using pointers..... appreciated. thanks. maybe along lines of
uint16* pntr1 =&storage1.cntlog1.posedge;
but pic32 compiler doesn't "&"
one possible way common header file, i.d. common.h include in both "filea.c" , "fileb.c"
#ifndef common_h #define common_h extern uint16 *global_pulse_count; #endif /*common_h*/
in file "filea.c" have add 2 things:
1) reserve memory global variable (outside function body):
uint16 *global_pulse_count;
(note there no external here.)
2) within appropriate function (you have init()
function sure)
global_pulse_count = &pulse.count;
(assign address global pointer variable.)
afterwards can access (*global_pulse_count)
reading , writing both "filea.c" , "fileb.c".
hth