Sujet : Re: Named arguments in C
De : Bonita.Montero (at) *nospam* gmail.com (Bonita Montero)
Groupes : comp.lang.cDate : 04. Jul 2024, 14:37:06
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v668hs$2pg1p$1@raubtier-asyl.eternal-september.org>
References : 1 2 3 4 5 6 7
User-Agent : Mozilla Thunderbird
Am 04.07.2024 um 14:49 schrieb bart:
On 04/07/2024 12:12, Bonita Montero wrote:
Am 02.07.2024 um 18:53 schrieb Ivan Farlenkov:
I am a fan of being able to name parameters in languages that allow it. I am quite confident that this will never come to C. It /might/ make it into C++, but as people have been writing proposals to do so for 20 years at least, I am not holding my breath.
You can sort of already do it in C by using designated initializers and macros
#define foo(A, B, C, ...) do{\
stuct technical technical={\
var1=default1,\
var2=default2,\
var3=default3 __VA_OPT__(,)\
__VA_ARGS__\
}\
actual_foo(A, B, C, technical.var1, technical.var2, technical.var3)\
}while(0)
>
What an anquated language that this needs macros.
How do you do it in C++?
With a inline-function that returns an auto to make the inner type
accessible.