tech-kern archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
C hackery [was Re: Some changes to autoconfiguration APIs]
>> [...] statement expression [...]
> I think statement expressions can be a rather "dangerous"
> complication in C
I am moderately sure statement expressions don't exist in C, at least
as of C99; I believe them to be a gccism. (I have never seen a spec
for any later C, though I have seen it said they've included things I
think have no business in C, such as closures, so maybe.)
Many gccisms can be dangerous, indeed. Many of them - the same ones,
in some cases - can also be extremely useful and clarifying.
> 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".
I find them, combined with nested functions, useful in that the result
can be close to lambda functions:
n = map_sum_over(list, ({ int foo(struct thingy *x)
{ ...
return(n);
}
&foo; }));
However, some of the gcc variants I use produce either broken code or
broken debugging info when faced with that, so these days I am more
likely to make the function a nested function within a containing
block, creating a small block if necessary to keep point of definition
close to point of use.
> 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.
Personally, I think it's less "for variable numbers of parameters" and
more "for large numbers of parameters".
> Named parameters can be simulated in modern C with full structure
> passing:
...at the price of defining a special-purpose struct for each such
function, or at least each such argument signature, and losing
unused-argument warnings (possibly among others, though none others
come to mind immediately).
/~\ The ASCII Mouse
\ / Ribbon Campaign
X Against HTML mouse%rodents-montreal.org@localhost
/ \ Email! 7D C8 61 52 5D E7 2D 39 4E F1 31 3E E8 B3 27 4B
Home |
Main Index |
Thread Index |
Old Index