If I have a struct such as:
typedef struct bag {
int test;
} *bag;
Then if a function consumes bag. Let’s say:
int sample(bag *b) {
b->test ...
}
I get the error that I made a request for member ‘b’ in something that is not a structure or union. How do I fix this? I could cast b to a (struct bag *) but that seems unreasonable.
You just defined the type
bagto be a pointer to the typestruct bag. Thus, when you make a variable of typebag *b, you are effectively creating a variable of typestruct bag**. Either change your argument to bebag b, or do a double dereference for your member ((*b)->test).Edit
As another poster mentioned, you probably meant
typedef struct bag { ... } bag, then your original code will compile.