Reputation: 10067
I need to port some code from FreePascal to C. I'm a professional C developer but know nothing of Pascal. Most of the code can be ported quite easily but one line is giving me a headache. What exactly is this supposed to do:
New(newBack);
curBackPtr^ := newBack;
curBackPtr := @(newBack^.next);
What is confusing me here is the fact that newBack
is assigned to curBackPtr
and right after that newBack.next
is assigned to curBackPtr
without curBackPtr
ever being accessed. Isn't the first assignment superfluous then and can be safely removed? Or am I missing something here?
Upvotes: 3
Views: 284
Reputation: 28839
New(newBack);
Allocates memory for a newBack type and stores the pointer in newBack.
curBackPtr^ := newBack;
Assigns the newBack pointer to what curBackPtr points to.
curBackPtr := @(newBack^.next);
Assigns curBackPtr to point to newBack^.next, that is, to the next pointer itself, not to what it points to.
Upvotes: 0