4 ms·
> (size)(sizeof(x)[y]) Actually, and this is probably surprising to many, this is equivalent to (size)(sizeof ((x)[y])) sizeof is not a function but a un
by jstimpfle 3y ago
> (size)(sizeof(x)[y])
Actually, and this is probably surprising to many, this is equivalent to
(size)(sizeof ((x)[y]))
sizeof is not a function but a unary operator, and indexing (as well as function calling...) binds stronger than the sizeof operator. It is not a function, not even syntactically! Hence why I strongly prefer putting a space after the sizeof keyword, and to not use parens for the operand unless needed.
https://en.cppreference.com/w/c/language/operator_precedence https://en.cppreference.com/w/c/language/operator_precedence
So the "correct" way to define the macro is
#define sizeof(x) ((size)(sizeof (x)))