Andreas
Andreas

Reputation: 10067

FreePascal beginners issue

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

Answers (2)

Russell Zahniser
Russell Zahniser

Reputation: 16364

enter image description here

Upvotes: 8

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

Related Questions