Re: Named arguments in C

Liste des GroupesRevenir à l 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, 04:15:28
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240703200203.258@kylheku.com>
References : 1 2 3 4 5 6 7 8 9 10
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2024-07-04, Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
bart <bc@freeuk.com> writes:
[...]
It really needs language support. That has been done in C for
designated initialisers; named args are a similar feature, easier to
implement (they can only be one level deep for example) and IMO far
more useful.
>
Although there are a few extra problems with C because the extra info
needed (parameter names and default values) can appear in both the
definition, and any number of prototype declarations, which cannot in
conflict.
>
As I recall, we had this discussion here a while ago.  The fact that C
allows parameter names for a function definition to differ from those in
corresponding declarations is a bit inconvenient.  But what I recall
suggesting at the time is that the parameter names in a call need to be
consistent with the names in the visible declaration.
>
    void foo(int x, int y) {
        // ...
    }
>
    void foo(int xx, int yy);
>
    foo(xx: 10, yy: 20);

void (*pfoo)(int y, int x) = foo;

pfoo(xx: 10, yy: 20); // oops, arguments are silently reversed

Before we have named arguments, we have to somehow make name part of the
type, so that the above pointer initialization violates a constraint.

Problem:

   void foo(int, int);

   void (*foo1)(int y, int x) = foo;

   void (*foo2)(int x, int y) = foo;

The crux is that parameters/arguments which are /simultaneously/ named /and/
positional are a bad idea.

Keyword parmeters should be a separate new category, specially
declared, and understood not to be ordered. There should be no way
to pass by-order arguments to keyword parameters.

--
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