Re:Emulating Swift's “defer” in C, with Clang or GCC+Blocks
by Animats on Saturday October 10, 2015 @03:08PM
(#10366575)
It used to be
[ Parent
| on HN ]
Re:Emulating Swift's “defer” in C, with Clang or GCC+Blocks
by vbernat on Saturday October 10, 2015 @06:13PM
(#10367194)
Better use:
#define min(X, Y) \
({ typeof (X) x_ = (X); \
typeof (Y) y_ = (Y); \
(x_ < y_) ? x_ : y_; })
Re:Emulating Swift's “defer” in C, with Clang or GCC+Blocks
by pjmlp on Saturday October 10, 2015 @04:13PM
(#10366820)
Which is anything but safe.
Re:Emulating Swift's “defer” in C, with Clang or GCC+Blocks
by azinman2 on Saturday October 10, 2015 @05:52PM
(#10367140)
Can you explain more please?
Re:Emulating Swift's “defer” in C, with Clang or GCC+Blocks
by copascetic on Saturday October 10, 2015 @06:08PM
(#10367180)
Because a macro in C/C++ is just text expansion, the given implementation will evaluate its arguments more than once, which will not be obvious at the "call" site and could have unintended consequences if the expressions have side-effects.