Assuming I have a struct
typedef struct
{
unsigned char mem1;
unsigned char *mem2
} MEMBERS;
where
unsigned sample = 12
MEMBERS memvalues = { 0x15 , &sample };
I need to access both values mem1 and mem2, when a function “GET_MEM” returns the address of the structure “MEMBERS” to X_mem. What I mean is this:
unsigned char *X_mem = GET_MEM ( ); //function returns address of memvalues
unsigned value1 = *X-mem;
unsigned Value2 = *++X_mem;
I want value1 to give 0x15, and value2 gives 12.
How can I make this work?
NOTE: Please do not assume the above code example to be syntactically correct. Its just to express my intention.
Thanks Folks.
You need to cast the incorrectly typed pointer returned by
GET_MEM():