Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #101031 > unrolled thread

Poor-man's named parameters with compound literals and designated initializers

Started byluser droog <luser.droog@gmail.com>
First post2017-01-03 12:43 -0800
Last post2017-01-03 15:06 -0800
Articles 3 — 3 participants

Back to article view | Back to comp.lang.c


Contents

  Poor-man's named parameters with compound literals and designated initializers luser droog <luser.droog@gmail.com> - 2017-01-03 12:43 -0800
    Re: Poor-man's named parameters with compound literals and designated initializers BartC <bc@freeuk.com> - 2017-01-03 22:53 +0000
      Re: Poor-man's named parameters with compound literals and designated initializers Keith Thompson <kst-u@mib.org> - 2017-01-03 15:06 -0800

#101031 — Poor-man's named parameters with compound literals and designated initializers

Fromluser droog <luser.droog@gmail.com>
Date2017-01-03 12:43 -0800
SubjectPoor-man's named parameters with compound literals and designated initializers
Message-ID<5a44ef82-defa-4766-8c1f-c280d5855f2c@googlegroups.com>
int
myfunc( struct args ){
    ...
}

struct args {
    int par1;
    int par2;
};

...

    (void)myfunc( (struct args){ .par1 = 42, .par2 = 7 } );

-- 
et voila
ou viola
si tu veut

[toc] | [next] | [standalone]


#101051

FromBartC <bc@freeuk.com>
Date2017-01-03 22:53 +0000
Message-ID<o4h9u3$guu$1@dont-email.me>
In reply to#101031
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.

(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.)

-- 
Bartc

[toc] | [prev] | [next] | [standalone]


#101054

FromKeith Thompson <kst-u@mib.org>
Date2017-01-03 15:06 -0800
Message-ID<lnk2abu4j2.fsf@kst-u.example.com>
In reply to#101051
BartC <bc@freeuk.com> 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  <http://www.ghoti.net/~kst>
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"

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.c


csiph-web