Story

On air. The free wire runs 15 minutes behind live. See pricing

World, crypto, finance and tech news, scored for impact.

TechHacker NewsFiled 16 h ago

C’s designated initializers give us named arguments

Open the sourceReported by Hacker News, quuxplusone.github.io, 18 November 2026

Not investment advice. Muhabbit scores how much a story may matter, not which way to trade.

C programmer Ben Klemens’ 2014 book 21st Century C documents a macro idiom that turns C’s designated initializers into named, defaultable function arguments, using a struct of parameters such as pressure, moles and temperature for an ideal-gas volume calculation. The technique exploits two C features excluded from C++20: designators may appear in any order, and repeated designators are permitted so that only the last value takes effect, letting callers override defaults through natural call syntax. Because defaults live in a macro rather than the function signature, adding a new field to the argument struct does not break existing call sites, though it does change the ABI, so callers must be recompiled against the updated header. Clang flags the intentional overrides with its default -Winitializer-overrides warning, while GCC issues -Woverride-init only under -Wextra. The same argument struct can be shared across a family of related functions, such as an ideal-pressure variant. Watch for adoption of the pattern in C libraries and for compiler warning behavior around deliberate initializer overrides.

Muhabbit's AI wrote this summary in its own words from Hacker News's report. It can get details wrong, so check the source.

Named in this story

21st Century C, Ben Klemens, Clang, GCC