0

I have a queue that stores thread structures

struct x
{
    int n;
    char *c;
    void *f;

};

The function below returns a structure defined as the following:

struct s {
    void *data;
};

When I call *new = allocate(&x_ptr), how can I access the members of x?

I tried the following but it does not work:

printf("%d\n", new ->data->n)

I get this error: request for member ‘n’ in something not a structure or union

1 Answer 1

1

data has type of void *, you need to cast it to the correct pointer type (assuming it is referencing a valid object of that type).

printf("%d\n", node->data->threadid);

---->

printf("%d\n", ((threaddesc *)(node->data))->threadid);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.