gcc 4.7.2
c89
你好,
我正在尝试取消引用指向结构指针的指针,并且在执行以下操作时收到此错误消息:
LOG_INFO("CHANNEL ID --- %d", *channel->id);
编译错误
request for member ‘id’ in something not a structure or union
如果我尝试将其转换为正确的指针类型,我仍然会收到相同的错误消息:
LOG_INFO("CHANNEL ID --- %d", (*(channel_t*)channel->id));
我通过声明一个新变量并分配结构指向的地址解决了这个问题:
channel_t *ch = NULL;
ch = *channel;
LOG_INFO("CHANNEL ID --- %d", ch->id);
我只是想知道为什么前两种方法失败了。
非常感谢您的任何建议,
结构体:
typedef struct tag_channel channel_t;
struct tag_channel {
size_t id;
char *name;
};
我这样称呼它:
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");
而这个功能,我遇到了麻烦:
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;
}