gcc 4.7.2
c89
Hello,
I am trying to dereference a pointer to a pointer to a structure, and I get this error message when I do the following:
LOG_INFO("CHANNEL ID --- %d", *channel->id);
Compile error
request for member ‘id’ in something not a structure or union
If I try and cast it to the correct pointer type, I still get the same error message:
LOG_INFO("CHANNEL ID --- %d", (*(channel_t*)channel->id));
I solved the problem by declaring a new variable and assigning the address of where the structure is pointing to:
channel_t *ch = NULL;
ch = *channel;
LOG_INFO("CHANNEL ID --- %d", ch->id);
I am just wondering why the first two methods failed.
Many thanks for any suggestions,
structure:
typedef struct tag_channel channel_t;
struct tag_channel {
size_t id;
char *name;
};
The way I am calling it:
channel_t *channel = NULL;
channel = (channel_t*)apr_pcalloc(mem_pool, sizeof *channel);
LOG_CHECK(job_queue_pop(queue, &channel) == TRUE, "Failed to pop from the queue");
And the function, I am having trouble with:
apr_status_t job_queue_pop(apr_queue_t *queue, channel_t **channel)
{
apr_status_t rv = 0;
channel_t *ch = NULL;
rv = apr_queue_pop(queue, (void**)channel);
if(rv != APR_SUCCESS) {
char err_buf[BUFFER_SIZE];
LOG_ERR("Failed to pop from the queue %s", apr_strerror(rv, err_buf, BUFFER_SIZE));
return FALSE;
}
ch = *channel;
LOG_INFO("CHANNEL ID --- %d", ch->id);
LOG_INFO("CHANNEL NAME - %s", ch->name);
return TRUE;
}
You have the precedence wrong, it should be e.g.
(*channel)->id
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With