Every story and comment from the Hacker News API, in a layout borrowed from 2001.
A comment on Type-safe generic data structures in C. Parent comment
If you can assume a compiler with statement expressions and typeof (gcc, clang, probably icc in this case):
#define SQ(x) ({ typeof(x) x_ = (x); x_ * x_ })
If not (MSVC++) then best of luck.
Anyway I 100% agree people way, way overuse macros. Very often a static inline function is a better trade-off.
There are no comments on this comment yet.
If you can assume a compiler with statement expressions and typeof (gcc, clang, probably icc in this case):
#define SQ(x) ({ typeof(x) x_ = (x); x_ * x_ })
If not (MSVC++) then best of luck.
Anyway I 100% agree people way, way overuse macros. Very often a static inline function is a better trade-off.