Re:Why Rust closures are somewhat hard
by whyever on Monday September 10, 2018 @03:40PM
(#17954509)
C does not have `auto`, so you couldn't store closures in local variables.
[ Parent
| on HN ]
Re:Why Rust closures are somewhat hard
by v_lisivka on Monday September 10, 2018 @03:54PM
(#17954642)
In C, you can use typeof().
#define max(a,b) \
({ typeof (a) _a = (a); \
typeof (b) _b = (b); \
_a > _b ? _a : _b; })
https://gcc.gnu.org/onlinedocs/gcc/Typeof.htmltypeof is supported by everything[1] except the C standard. It was rejected in the 1990s and nobody on the committee seems to want to revisit the decision.
To be fair, typeof is not as useful without statement expressions (`({ ... })`), and statement expressions aren't as widely supported.
[1] All the major compilers support it (clang, GCC, IBM, Intel, Microsoft, Solaris, etc), plus or minus underscores in the identifier.
Re:Why Rust closures are somewhat hard
by Longhanks on Monday September 10, 2018 @04:02PM
(#17954723)
You’re not wrong, but C has __auto_type (at least GCC and clang support it, no idea about MSVC): https://gcc.gnu.org/onlinedocs/gcc/Typeof.html