liveBook · Manning

Arrow operator

As explained in Modern C

The arrow operator is the C operator that accesses a structure or union member through a pointer to that aggregate.

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

How Modern C covers it

How deep it goes
Defines syntax, equivalence with (*pointer).member, result type, and practical examples without descending into pointer internals.
Examples
Uses timespec_diff and rational-number functions including rat_destroy, rat_normalize, rat_extend, and rat_sumup.
What it assumes
Assumes familiarity with pointers, structures, member access, and pointer parameters.
What you can do after
Apply it in C to read or modify structure and union members through pointers.
How it connects
Connects pointers with structures, unions, member access, null-pointer checks, and rational-number operations.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C. The section links point to the parts of the book it draws on.