recently, while reading former’s code in my current project, I encounter the problems below:
while implementing the Queue, my former wrote codes like this:
while(uq->pHead)
{
char *tmp = uq->pHead;
uq->pHead = *(char **)tmp;
//...
}
the uq->pHead has definition like:
typedef struct {
char* pHead;
//...
} Queue;
Well, I’m quite confused about the usage that “uq->pHead = *(char**)tmp” , could anyone explain it to me in detail?
if we assume that *(uq->pHead) = 32(i.e. ‘ ‘) , *(char**)tmp would translate this into pointer-form, but…how could it make sense?
Thanks a lot.
Let’s suppose that we’re implementing your Queue as a linked list. We might have:
To empty the linked list, we might write:
Now suppose we don’t really care about maintainable code, or are otherwise being lazy. We might instead just figure any pointer would do, and keep the structure for ‘node’ in our head, and write: