Hi Derek, On 2026-01-28T15:46:08-0500, Derek Martin wrote:
[...] > - sizeof IS NOT A FUNCTION[*]. Do not format it like one, i.e. use: > ✓ sizeof varname // no, doesn't need parens > ✓ sizeof (type name) // parens needed, but not a function call! > ✓ struct foo *x; size_t s = sizeof *x; // doesn't need parens or to be > initialized/non-null! Being a function is orthogonal to needing parentheses or not, as you show in your comment about type names. For consistency, it is better to always use parens, since you need them in half of the cases. Operators not requiring parentheses complicate parsing in compilers and is a historic accident that can't be removed, but that is not ideal either. FWIW, the C Committee considered disallowing unparenthesized sizeof. Also, here's some history: - V1 Unix didn't have any C. - V2 Unix had C code. It didn't have sizeof. But it had 'return'. return() required parentheses (or at least all the source code used them; I assume it required them). - V3 Unix and V4 Unix were like V2. - V5 Unix added sizeof, with the syntax we have today. return() continued having parentheses. - V6 Unix was like V5. - V7 Unix removed parentheses from return. So, this is not about functions or not; it's just arbitrary historic details. We recently added a new operator in C2y: _Countof. We seriously considered breaking consistency and requiring parentheses for all uses. In the end I didn't, just because it was simpler to paste the parsing code from sizeof(), but we were quite tempted. Have a lovely night! Alex -- <https://www.alejandro-colomar.es>
signature.asc
Description: PGP signature
