Why do I get this warning when assigning an anonymous function to a pointer to function field in my struct?
Here are my structs:
typedef struct list_node_t {...} ListNode;
typedef struct list_t {
ListNode* head;
ListNode* current;
...
//pointer to function fields
int (*hasNext)();
...
}List;
And here I assign an anonymous function to hasNext. It causes the warning.
List* makeNewList( ){
List* list = (List*)malloc(sizeof(List));
list->head = list->tail = NULL;
list->current = list->head;
list->hasNext = (int (*)(void)) (list->current==list->tail? 0:1);
return list;
}
compiling with gcc -c -Wall list.c respond with this message:
list.c: In function ‘makeNewList’:
list.c:35:21: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
list->hasNext = (int (*)(void)) (list->current==list->tail? 0:1);
Why? I want list->hasNext to be a pointer to a function returning int, not a scalar int. What am I doing wrong?