Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Poor-man's named parameters with compound literals and designated initializers Date: Tue, 03 Jan 2017 15:06:57 -0800 Organization: None to speak of Lines: 32 Message-ID: References: <5a44ef82-defa-4766-8c1f-c280d5855f2c@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="167f7d05f22907ea8e3985ed50c4ed73"; logging-data="9414"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18OTfub0tQJOQVVlxYG6hgj" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:p73/xMpjbSoReKUUQv3+aCsLwGo= sha1:ssKtujNCtiMoqdXZoKQ+Jg+QjR4= Xref: csiph.com comp.lang.c:101054 BartC writes: > On 03/01/2017 20:43, luser droog wrote: >> >> int >> myfunc( struct args ){ >> ... >> } >> >> struct args { >> int par1; >> int par2; >> }; >> >> ... >> >> (void)myfunc( (struct args){ .par1 = 42, .par2 = 7 } ); > > You need Thiago Adam's struct member defaults to go with it. They're not absolutely needed. Any omitted members default to zero. You can often (but not always) arrange for that to be a meaningful default value. > (This might tick a box but it's generally unwieldy compared to the real > thing. However, when they added designated initialisers, they could have > introduced named parameters at the same time.) -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"