In C, I often come across errors with code like this
prio_queue->head[index] = newEntry;
Yields a " "Cannot assign Entry** to Entry* " How do you prevent/debug errors of this type, in general?
|
In C, I often come across errors with code like this
Yields a " "Cannot assign Entry** to Entry* " How do you prevent/debug errors of this type, in general? |
|||||||||||||||||||
|
|
If head is an array of elements, and index is < size of that array, and newEntry is of the same type as the array, and prio_queue is a pointer to a data structure containing head, then there nothing wrong with this code. A lot of ifs, but without knowing your data structures, I (and no one else) can tell if it's right or wrong. Update: Based on the update to the question, a strategy would be to keep careful track of how many levels of indirection a variable has. |
|||||||
|
|
There are two types of problems you may run into:
Your problem looks like compilation problem than run time so it looks more like data type mismatch problem mostly but we need more information to dig up this. Please elaborate. |
|||
|
|
|
I've been away from a C compiler for quite a few years, but isn't it telling you that prio_queue->head[index] is a pointer to Entry and newEntry is a pointer to a pointer to Entry? Try: prio_queue->head[index] = *newEntry; |
|||
|
This particular issue comes down to knowing the types of the respective expressions, and there are no shortcuts to that; either you know it or you don't. The question to answer is why the types are different in the first place; that indicates that someone was a bit confused when they wrote the code. |
|||
|
|