すべてが1つのCファイルにある場合、次のコードが正常にコンパイルされる理由を誰かに説明してもらえますか?しかし、make_queue_data()関数を別のCファイルに入れてコンパイルすると、「代入は整数からポインタを作成します」キャストなし」警告?
#include <stdlib.h>
#include <stdio.h>
typedef struct pqueue_data_t
{
int priority;
void *queue_data;
} pqueue_data_t;
void*
safe_malloc (size_t size)
{
void *mem_block = NULL;
if ((mem_block = calloc (1, size)) == NULL) {
fprintf (stderr, "ERROR: safe_malloc() cannot allocate memory.");
exit (EXIT_FAILURE);
}
return (mem_block);
}
pqueue_data_t *
make_queue_data(void *data, int priority)
{
pqueue_data_t *pdata;
pdata = (pqueue_data_t *) safe_malloc(sizeof(pqueue_data_t));
pdata->priority = priority;
pdata->queue_data = data;
return (pdata);
}
int *
alloc_data (int val)
{
int *rv = (int *)safe_malloc(sizeof(int));
*rv = val;
return (rv);
}
int
main (int argc, char **argv)
{
pqueue_data_t *temp;
temp = make_queue_data(alloc_data(34), 0); /* problem line */
printf("%d\n", *((int *)temp->queue_data));
return EXIT_SUCCESS;
}
これは私のコード全体ではありません。関連する部分を切り取って貼り付けただけです。
問題がどこにあるかを見つけようとして数時間この壁に頭をぶつけていたので、どんな助けも大歓迎です..