At Fri, 30 Apr 2021 23:05:48 -0400 (EDT), Mouse <mouse%Rodents-Montreal.ORG@localhost> wrote:
Subject: Re: Some changes to autoconfiguration APIs
>
> However, I see little reason to do the
> statement expression rather than
>
> { static const struct cfargs foo = { ... };
> config_found(..., &foo);
> }
That's a very good point!
I think statement expressions can be a rather "dangerous" complication
in C -- I've only ever found them to be truly useful within a macro when
I'm trying to avoid, or do something different than, the "usual
promotions".
Kind of related to this, I have the following comment in my notes about C:
- Positional parameters are evil (or at least error prone), especially
for variable numbers of parameters.
Named parameters can be simulated in modern C with full structure
passing:
struct fooness {
int blah;
};
struct somefunc_params {
char *p1;
int i1;
struct fooness foo;
};
int
somefunc(struct somefunc_params p)
{
if (p.i1)
printf("%s", p.p1);
return 0;
}
res = somefunc((struct somefunc_params)
{.p1 = "foo",
.i1 = 1,
.foo = (struct fooness) {.blah = 4}});
A working example with more rants and ravings about C, and some other
ideas about hiding the struct references within the function
implementation is here:
https://github.com/robohack/experiments/blob/master/tc99namedparams.c
--
Greg A. Woods <gwoods%acm.org@localhost>
Kelowna, BC +1 250 762-7675 RoboHack <woods%robohack.ca@localhost>
Planix, Inc. <woods%planix.com@localhost> Avoncote Farms <woods%avoncote.ca@localhost>
Attachment:
pgp25YtIjV6re.pgp
Description: OpenPGP Digital Signature