c - pointer from integer without a cast warning -
can please explain me why following code compile fine when in 1 c file, when put make_queue_data() function c file , compile it, gives me "assignment makes pointer integer without 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 whole of code, cut , pasted relevant parts one.
any appreciated, have been bashing head against wall couple of hours trying find problem is..
it might (and here i'm guessing) because don't have prototype of safe_malloc in other source file.
or might because don't have pqueue_data_t defined in other source file (it should in header file instead).
Comments
Post a Comment