<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/c-s-designated-initializers-give-us-named-arguments-fk50skqob" -->

---
title: C’s designated initializers give us named arguments
description: C's designated initializers can simulate named, defaultable function arguments using a struct and a macro wrapper. The pattern relies on two C-specific...
canonical: https://daily.dev/posts/c-s-designated-initializers-give-us-named-arguments-fk50skqob
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: C’s designated initializers give us named arguments | daily.dev
og:description: C's designated initializers can simulate named, defaultable function arguments using a struct and a macro wrapper. The pattern relies on two C-specific...
og:url: https://daily.dev/posts/c-s-designated-initializers-give-us-named-arguments-fk50skqob
og:image: https://api.daily.dev/og/posts/fk50SkqOb.png
og:image:alt: C’s designated initializers give us named arguments
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# C’s designated initializers give us named arguments

**[Arthur O'Dwyer](https://daily.dev/sources/quuxplusone)** · 4 min read · 1 upvotes · 0 comments

## Summary

C's designated initializers can simulate named, defaultable function arguments using a struct and a macro wrapper. The pattern relies on two C-specific features C++20 didn't adopt: designators can appear in any order, and repeated designators let the last one win. A macro builds a compound literal with default values, then calls the real function, so `ideal_volume(.kelvin = 373.15)` works like a keyword argument. Adding a new named parameter later is no longer an API break, though it is an ABI break since callers must recompile. The author calls it 'heavyweight' and 'cute' compared to a plain function, but found real uses in gab462/hof-flecs-raylib and EpicGames/raddebugger.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://quuxplusone.github.io/blog/2026/11/16/named-arguments-in-c>

## Questions this post answers

### how can I simulate named arguments with default values in C

Define a struct of the parameters, give it default values inside a variadic macro that builds a compound literal, then pass that struct to the real function. Because C's designated initializers can appear in any order and a repeated designator overrides earlier ones, callers can write things like `ideal_volume(.kelvin = 373.15)` and only override the fields they care about.

_Developers piecing together C idioms like this one often compare notes and examples on daily.dev._

### does adding a new field to a C args struct used with designated initializers break existing callers

No, adding a new named field to the arguments struct is not an API break since old call sites using designated initializers still compile and behave the same. It is however an ABI break: existing compiled callers must be recompiled against the updated header to pick up the new struct layout.

_Anyone weighing API versus ABI compatibility tradeoffs in C can track idioms like this on daily.dev._

### can C designated initializers appear in any order or be repeated

Yes. Designated initializers in a C compound literal can be listed in any order, so `.atm=1, .moles=2` means the same as `.moles=2, .atm=1`. The same designator can also appear more than once, with only the last occurrence taking effect, for example `.atm=1, .moles=2, .atm=3` behaves like `.atm=3, .moles=2`. C++20 did not adopt either of these two behaviors.

_C developers comparing language features against C++20 can follow details like these on daily.dev._

## Community take

How the wider developer community reacted, aggregated from 2 discussions and 84 comments across hackernews, lobsters (as of 2026-11-19).

**TL;DR:** Developers broadly recognize this designated-initializer trick as a well-known, pragmatic C idiom (seen in sokol, Zig-style option structs, Tsoding's code, etc.), while a long side-thread compares it unfavorably and favorably to C++20's stricter in-order designated initializers.

**Sentiment:** 40% positive · 45% mixed · 15% skeptical

**The case for**

- Several note this pattern (option-bag structs with designated initializers) has been used productively for years, e.g. in the sokol headers and Zig-style APIs.
- It's seen as a cheap way to get ABI-stable, extensible APIs since structs are just stack-allocated and passed by pointer under the hood.
- Similar tag-list/extension-struct patterns (Amiga tag lists, Vulkan's pNext chains, GLX attribute arrays) are cited as longstanding precedent for extensible APIs without breaking ABI.

**The pushback**

- Some call the macro-wrapping approach a hack that changes the calling convention and adds real overhead when functions aren't inlined.
- C++'s equivalent requires designators in order, which several found more arbitrary or annoying depending on perspective, fueling a long tangential debate.
- Allowing repeated/overridden designators could lead to subtle bugs, e.g. duplicate-field mistakes from copy-pasting.
- One commenter raised that the article's author has serious personal allegations against them, souring their view of engaging with the content.

**By community**

- hackernews (mixed): Discussion mostly veers into a detailed, sometimes heated comparison of C vs C++20 designated initializers and related extensible-API idioms (Amiga tag lists, Vulkan, OpenGL), with some practical concerns about overhead and bugs.
- lobsters (mixed): Several find the pattern genuinely useful and common (sokol/Zig-style option structs), but the top comment raises serious objections to the article's author, and others debate C++'s equivalent approach.

**Hottest debate:** Whether C++20's requirement that designated initializers appear in struct-definition order is a sensible safety feature or an arbitrary, worse-than-C design choice.

**Open questions**

- Are there clear guidelines for when this struct+macro pattern is worth the overhead versus just using plain function arguments?
- How much real performance overhead does passing option structs by value actually add in practice when functions aren't inlined?

**Highlights**

> the author of the article is a known rapist who got caught with child porn years ago. im not sure what the criteria for banning websites is on lobsters. but it'd be lovely if i could never see his name or blog again.
> — [sarah-quinones on lobsters · 29 points](https://lobste.rs/s/kktn5b/c_s_designated_initializers_give_us_named#c_v4v5xc)

> Tbh I would skip all the preprocessor magic proposed in the article and just go for plain C99 'option bag struct' arguments, the called function only needs to be aware that "zero means default". I've been using this style for almost 10 years now in the sokol headers, and it still feels like the right thing to do and actually more ergonomic than most other languages for initializing complex structs, e.g. see here for creating a 3D render pipeline object with dozens of creation options, but most of them keeping their default values:     state.pip = sg_make_pipeline(&(sg_pipeline_desc){         .layout = {             .attrs = {                 [ATTR_texcube_pos].format = SG_VERTEXFORMAT_FLOAT3,                 [ATTR_texcube_color0].format = SG_VERTEXFORMAT_UBYTE4N,                 [ATTR_texcube_texcoord0].format = SG_VERTEXFORMAT_SHORT2N             }         },         .shader = shd,         .index_type = SG_INDEXTYPE_UINT16,         .cull_mode = SG_CULLMODE_BACK,         .depth = {             .compare = SG_COMPAREFUNC_LESS_EQUAL,             .write_enabled = true         },         .label = "texcube-pipeline"     }); (or see here: https://github.com/floooh/sokol-samples/blob/11bbe1a6865e93c...) ...this code snippet also makes use of C99 features that are not available in C++20 though (or most other languages), and it's really remarkable how well designed the C99 designated init feature as a whole is (even though it was an afterthought) and how badly its individual subfeatures were understood by most later languages (basically, only Odin got it "mostly right": https://github.com/floooh/sokol-odin/blob/7d47a31cad83a26ba1...)
> — [flohofwoe on hackernews](https://news.ycombinator.com/item?id=50560704)

> That doesn't stop the C++ committee from doing the obvious, trivial and correct thing.   Point foo = {      .y = foo(),      .x = bar(),   }; calls foo(), sets x to it, calls bar(), and sets y to it. And   Point foo = {      .x = bar(),      .y = foo(),   }; calls bar(), sets x to it, then calls foo(), and sets y to it. I'm sure you can give me the reason they didn't do that, and it will be something like "this conflicts with LRR-value warp semantics when invoked from concept inside a consteval coroutine" or something equally stupid, but the problem is I don't care. This is a good piece of syntax sugar (and the only reason I use C++20) and it's being handicapped by insane features that I don't use and don't care about.
> — [sorrywhat on hackernews · 1 comments](https://news.ycombinator.com/item?id=50561901)

> The macro is cute, but passing structures by value like that is going to cause real measurable overhead where the functions don't get inlined (the author sort of admits this I guess by calling it "heavyweight").
> — [jcalvinowens on hackernews](https://news.ycombinator.com/item?id=50562157)

**Source threads**

- [hackernews](https://news.ycombinator.com/item?id=50544168) · 44 points · 74 comments
- [lobsters](https://lobste.rs/s/kktn5b/c_s_designated_initializers_give_us_named) · 14 points · 10 comments

## Similar posts on daily.dev

- [Named and Optional Arguments are Awesome](https://daily.dev/posts/named-and-optional-arguments-are-awesome-ndmndouei) · Lobsters · 0 upvotes · 0 comments
- [Fun with designated initializers](https://daily.dev/posts/fun-with-designated-initializers-muciazvbs) · Arthur O'Dwyer · 0 upvotes · 0 comments
- [We Have Named Arguments at Home](https://daily.dev/posts/we-have-named-arguments-at-home-rkawezkub) · corrode · 3 upvotes · 0 comments
- [Arguing about arguments](https://daily.dev/posts/arguing-about-arguments-pajlneklj) · Steve Klabnik · 0 upvotes · 0 comments

---

Tags: [#architecture](https://daily.dev/tags/architecture), [#c](https://daily.dev/tags/c)

[View this post on daily.dev](https://daily.dev/posts/c-s-designated-initializers-give-us-named-arguments-fk50skqob)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"C’s designated initializers give us named arguments","url":"https://daily.dev/posts/c-s-designated-initializers-give-us-named-arguments-fk50skqob","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/c-s-designated-initializers-give-us-named-arguments-fk50skqob"},"datePublished":"2026-11-16T16:33:28.575Z","dateModified":"2026-11-19T16:43:40.748Z","description":"C's designated initializers can simulate named, defaultable function arguments using a struct and a macro wrapper. The pattern relies on two C-specific...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/e3a9783d2dc46301158849c96a3b989b?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/e3a9783d2dc46301158849c96a3b989b?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Arthur O'Dwyer","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Arthur O'Dwyer","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/a789aa2fcdb64c219980d6d6901791e9","url":"https://daily.dev/sources/quuxplusone"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/c-s-designated-initializers-give-us-named-arguments-fk50skqob","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"architecture,c","timeRequired":"PT4M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Arthur O'Dwyer","item":"https://daily.dev/sources/quuxplusone"},{"@type":"ListItem","position":3,"name":"C’s designated initializers give us named arguments"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/c-s-designated-initializers-give-us-named-arguments-fk50skqob#faq","mainEntity":[{"@type":"Question","name":"how can I simulate named arguments with default values in C","acceptedAnswer":{"@type":"Answer","text":"Define a struct of the parameters, give it default values inside a variadic macro that builds a compound literal, then pass that struct to the real function. Because C's designated initializers can appear in any order and a repeated designator overrides earlier ones, callers can write things like `ideal_volume(.kelvin = 373.15)` and only override the fields they care about. Developers piecing together C idioms like this one often compare notes and examples on daily.dev."}},{"@type":"Question","name":"does adding a new field to a C args struct used with designated initializers break existing callers","acceptedAnswer":{"@type":"Answer","text":"No, adding a new named field to the arguments struct is not an API break since old call sites using designated initializers still compile and behave the same. It is however an ABI break: existing compiled callers must be recompiled against the updated header to pick up the new struct layout. Anyone weighing API versus ABI compatibility tradeoffs in C can track idioms like this on daily.dev."}},{"@type":"Question","name":"can C designated initializers appear in any order or be repeated","acceptedAnswer":{"@type":"Answer","text":"Yes. Designated initializers in a C compound literal can be listed in any order, so `.atm=1, .moles=2` means the same as `.moles=2, .atm=1`. The same designator can also appear more than once, with only the last occurrence taking effect, for example `.atm=1, .moles=2, .atm=3` behaves like `.atm=3, .moles=2`. C++20 did not adopt either of these two behaviors. C developers comparing language features against C++20 can follow details like these on daily.dev."}}]}
```

