Re: Named arguments in C

Liste des GroupesRevenir à cl c 
Sujet : Re: Named arguments in C
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.c
Date : 04. Jul 2024, 10:25:14
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240704022251.163@kylheku.com>
References : 1 2 3 4 5 6 7 8 9
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2024-07-04, Richard Harnden <richard.nospam@gmail.invalid> wrote:
On 03/07/2024 21:16, Blue-Maned_Hawk wrote:
Richard Harnden wrote:
 
On 02/07/2024 20:39, Blue-Maned_Hawk wrote:
>
I searched around a bit, and it seems like a more common way to
implement named arguments in C is with a pattern like this:
>
#define f(...) f_impl((struct f_struct){__VA_ARGS__})
void f_impl(struct f_struct { int i, j;  char * k; double l, m, n; }
f_params)
{
/* actual code */
}
>
int main(void)
{
f(.i = 0, .j = 2, .l = 2.5, .k = "foo", .n = 4.2, .m = 2.5);
}
>
>
That's the kind of thing Bonita would write.
Horrible.
 
I assure you that i can write much worse code.  What do you say makes this
is horrible?
>
It just doesn't feel like how C ought to be, not to me anyway.
>
If you have named parameters, then you have to allow default values.
Then you have function overloading.

Whether or not a parameter is required or optional is orthogonal as to
whether or not it is a keyword/named parameter.

Some languages have fixed positional parameters accompanied by an
optional bag of keywords. The keywords may be numerous and so need to be
treated as optional with defaults.

The design of those languages is not the only possible point in the
design space.

We can conceive of keyword parameters being all required.


--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Date Sujet#  Auteur
2 Jul 24 * Named arguments in C22Ivan Farlenkov
2 Jul 24 +* Re: Named arguments in C12Blue-Maned_Hawk
2 Jul 24 i+* Re: Named arguments in C4Richard Harnden
3 Jul 24 ii`* Re: Named arguments in C3Blue-Maned_Hawk
4 Jul 24 ii `* Re: Named arguments in C2Richard Harnden
4 Jul 24 ii  `- Re: Named arguments in C1Kaz Kylheku
2 Jul 24 i`* Re: Named arguments in C7bart
2 Jul 24 i +- Re: Named arguments in C1Keith Thompson
3 Jul 24 i +* Re: Named arguments in C4Blue-Maned_Hawk
4 Jul 24 i i`* Re: Named arguments in C3bart
4 Jul 24 i i `* Re: Named arguments in C2Keith Thompson
4 Jul 24 i i  `- Re: Named arguments in C1Kaz Kylheku
4 Jul 24 i `- Re: Named arguments in C1Opus
3 Jul 24 +- Re: Named arguments in C1Lawrence D'Oliveiro
4 Jul 24 `* Re: Named arguments in C8Bonita Montero
4 Jul 24  +* Re: Named arguments in C2Michael S
4 Jul 24  i`- Re: Named arguments in C1Michael S
4 Jul 24  `* Re: Named arguments in C5bart
4 Jul 24   `* Re: Named arguments in C4Bonita Montero
4 Jul 24    +- Re: Named arguments in C1Bonita Montero
4 Jul 24    `* Re: Named arguments in C2bart
4 Jul 24     `- Re: Named arguments in C1Bonita Montero

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal