Deutsch English Français Italiano |
<v65o9n$2mjeq$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Richard Harnden <richard.nospam@gmail.invalid> Newsgroups: comp.lang.c Subject: Re: Named arguments in C Date: Thu, 4 Jul 2024 09:59:35 +0100 Organization: A noiseless patient Spider Lines: 38 Message-ID: <v65o9n$2mjeq$1@dont-email.me> 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> <v61la7$1p1hu$1@dont-email.me> <pan$9627a$afbb0d44$f2f0aac5$8cdb0dac@invalid.invalid> Reply-To: nospam.harnden@invalid.com MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Thu, 04 Jul 2024 10:59:35 +0200 (CEST) Injection-Info: dont-email.me; posting-host="2a07946bd72f9173d4333be6f21dfbcc"; logging-data="2837978"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/XMKDodBH+DXEVcul+ZFBdvMH10caDbUY=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:Up1wj/OCeTfKMcQCCcD+4ZWilAM= Content-Language: en-GB In-Reply-To: <pan$9627a$afbb0d44$f2f0aac5$8cdb0dac@invalid.invalid> Bytes: 2409 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. I mostly try to avoid function-like macros - this would force them to be everywhere - and the definition would be far away from the call. I agree with Bart downthread ...