Deutsch   English   Français   Italiano  
<20240703200203.258@kylheku.com>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!feeds.phibee-telecom.net!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Kaz Kylheku <643-408-1753@kylheku.com>
Newsgroups: comp.lang.c
Subject: Re: Named arguments in C
Date: Thu, 4 Jul 2024 03:15:28 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 53
Message-ID: <20240703200203.258@kylheku.com>
References: <utgjh0$21nsq$2@dont-email.me> <uth66l$266da$1@dont-email.me>
 <uti83u$2ed01$4@dont-email.me> <utjhfn$2r0cr$1@dont-email.me>
 <v61bbh$1n9ij$1@dont-email.me>
 <pan$1e5a0$ef4a1faf$e6cedebc$3f30bac1@invalid.invalid>
 <v61lm8$1p1gs$1@dont-email.me>
 <pan$39bde$c80409dd$374fc6fd$c86207fe@invalid.invalid>
 <v64pdt$2dlb6$1@dont-email.me> <875xtlx44j.fsf@nosuchdomain.example.com>
Injection-Date: Thu, 04 Jul 2024 05:15:29 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="7d93d4bd8c515bc8a0f37a98cfd50244";
	logging-data="2730085"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19TBlZdzrmFgcEbomTju79BWRtihAyKHpQ="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:Z6i0DslPWqQNmvHSxL1h4zHYNEE=
Bytes: 3080

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