I am facing an error: request for member data in something not a structure or union. I am passing the address of a structure receiver_data
in a structure global_vals
to a function in another file.
The init_func
function receives the address as a pointer. I used the arrow operator since its a pointer but I cant seem to access the structure. Both memory addresses &val.receiver_data
and *ptr
are the same so I'm not quite sure where went wrong
Would appreciate if someone can point out my mistake.
The components are split across various source/ header files with the following structure.
- main.c
- func_init.c
- datatypes.c
main.c
global_vals val;
void main(void)
{
val.receiver_data.data = 10;
init_func(&val.receiver_data);
}
func_init.c
void init_func(int *ptr_data)
{
printf("%d\n", ptr_data->data);
}
datatypes.h
typedef struct Receiver {
int data;
} Receiver;
typedef struct {
Receiver receiver_data;
// truncated
} global_vals;