4 ms·
scrolling through http://git.suckless.org/st/plain/st.c http://git.suckless.org/st/plain/st.c I stumbled upon #define LEN(a) (sizeof(a) / sizeof(a)[0]) I
by daef 10y ago
scrolling through http://git.suckless.org/st/plain/st.c http://git.suckless.org/st/plain/st.c I stumbled upon
#define LEN(a) (sizeof(a) / sizeof(a)[0])
I know precompiler magic is hard, and my C aint the best
but it makes me wonder if the parens at the end make sense -
shouldn't it be something like
#define LEN(a) (sizeof(a) / sizeof((a)[0]))
also asked here https://stackoverflow.com/questions/42001665/is-this-a-plain-bug-or-a-clever-precompiler-trick https://stackoverflow.com/questions/42001665/is-this-a-plain...
- kv-1 10y agoi'm not saying that the way they wrote it makes sense, but you have to remember that sizeof is actually an operator and not a function.
- daef 10y agojust got basically the same answer on stackoverflow - sizeof is an operator -> works w/o parens - makes sense - that's why i'm asking
- deleted 10y ago[deleted]