3 ms·
It's a unary operator, kind of like ~ or !, which can apply to parenthesis (), until it meets a type, then the parenthesis are mandatory: int x; sizeof
by glouwbug 2mo ago
It's a unary operator, kind of like ~ or !, which can apply to parenthesis (), until it meets a type, then the parenthesis are mandatory:
int x;
sizeof x; // okay
sizeof (x); // okay
sizeof int; // not okay
sizeof (int); // okay
It's a weird double rule to parse, but even worse, the strongest binding precedence typically doesn't like an alpha identifier at that point in the recursive descent, so you get weird rules like:
read_prefix():
is peak() '!': ...
is peak() '~": ...
is alpha(peak())
maybe alpha is sizeof?
wait, it wasn't sizeof? it was an identifier? long rewind
is peak() '+': ...
Something like @ would've been a good pick for sizeof.
\ramble on
(actually, better yet, it should've been used instead of & for taking the address). Imagine:
int x;
int* p = @x;
\ramble off
- deleted 2mo ago[deleted]
- atiedebee 2mo agoIve actually toyed with the idea of having @ as a pointer dereference. It seems to make sense: you want to know what is at the address stored in p.