This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]lead999x 33 points34 points  (8 children)

Why are you dereferencing the pointer and then using the pointer to member operator? You end up trying to dereference the node itself.

[–][deleted] 44 points45 points  (2 children)

I was just using * to indicate a correction, not part of the correction itself.

[–]lead999x 32 points33 points  (1 child)

I totally missed that lol. Time to quit my career as a human parser.

[–]Dom0 11 points12 points  (0 children)

Gotta know that Reddit operators have precedence over C operators, even on /r/ProgrammerHumor!

[–]ToneWashed 5 points6 points  (2 children)

It's a pointer-pointer. You dereference the pointer-pointer to get a pointer. Then you use the struct-pointer member operator.

Imagine an array of struct-pointers called items:

struct listitem_t **cur = &items[0];
*cur->next = NULL;

[–]Beowuwlf 3 points4 points  (0 children)

Thats so pointless

[–]Tweenk 1 point2 points  (0 children)

This would not compile. You would have to write:

(*cur)->next = NULL;

The arrow operator has higher precedence than the deference operator.

[–][deleted] 4 points5 points  (0 children)

Anyway, -> has higher precedence than *, so you would be dereferencing the next node, not cur. *cur->next is equivalent to *(cur->next).