double timespec_diff(struct timespec const* later, struct timespec const* sooner) { return later->tv_sec - sooner->tv_sec; } Here, -> accesses a structure member through a pointer. It is equivalent to (*later).tv_sec, including the required parentheses. section 11.2
Accessing pointed-to members
The expression later->tv_sec is not itself a pointer; it produces the member object, whose type is long. The complete timespec_diff example also uses -> for tv_nsec and handles reversed times. section 11.2
TAKEAWAY
- Use pointer->member when the left operand points to a structure or union; use object.member when it does not. section 11.2
- Pointer-based rational-number functions use -> to modify members and may first test whether the pointer is null. section 11.2
