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;
}