Can someone please explain to me why the following code will compile fine when it is all in the one C file, but when i put the make_queue_data() function into another C file and compile it, it gives me an "assignment makes pointer from integer without a cast" warning?
#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;
}
this isnt the whole of my code, i just cut and pasted the relevant parts into the one.
any help would be greatly appreciated, as i have been bashing my head against this wall for a couple of hours trying to find where the problem is..