Zig's dot star syntax (value.*)

What value.* Means in Zig

  • Consensus that ptr.* is simply pointer dereference, analogous to *ptr in C.
  • Clarification that this applies regardless of whether memory is on the stack or heap; it’s general pointer dereferencing, not just “stack addresses”.
  • ptr.*.* is a double dereference.

Postfix vs Prefix Dereference

  • Supporters of p.* argue:
    • It preserves left‑to‑right reading, especially when mixed with field access and indexing.
    • It aligns with the idea that . already auto‑dereferences for field access; * is like a “field” meaning “the whole value”.
    • Postfix operators compose better with other postfix operations, reducing parentheses in pointer-heavy code.
  • Critics argue:
    • p.* is unintuitive and visually jarring to those used to *p.
    • There was no strong need to deviate from widely established *p / &p syntax.
    • Syntax looks like regex or pattern notation and may not obviously signal dereference.

Comparisons to Other Languages

  • Rust: discussion of foo.await vs await foo:
    • Pro‑suffix: better left‑to‑right flow and composition (foo.await.bar.await).
    • Anti‑suffix: more complex precedence, unclear at a glance that .await is a suspension point.
  • C:
    • C already has a postfix dereference via p[0], though it’s considered ugly.
    • Complaints about C’s “declaration follows use” pointer syntax and need for many parentheses.
    • Historical reasons for -> and lack of auto‑dereferencing with . are noted.
  • Pascal/Ada:
    • Pascal uses ^ as postfix dereference; Ada uses p.all, both seen as conceptually similar to Zig’s p.*.

Audience and Teaching Pointers

  • Some are surprised that many Zig users don’t know C or pointers; others point out most modern developers start with Python/JS and higher‑level stacks.
  • Debate over whether C should remain the canonical way to learn pointers versus teaching them first in Zig or Rust.
  • Several comments defend beginner‑oriented explanations and “discovering” low‑level concepts via Zig; others find the article too basic for HN or oddly avoids directly mapping to C.

Views on Zig’s Syntax Overall

  • Mixed feelings:
    • Some see Zig’s pointer and initialization syntax (.{ ... }) as cleaner and more consistent than C.
    • Others describe Zig syntax as “poor”, over‑punctuated, or different for its own sake, and express interest in C‑like alternatives (e.g., C3) or a “TypeScript for Zig”.