Re: Error in 'man operator'
From: David Sletten <hidden>
Date: 2021-08-28 00:20:25
Ha. Nice work. On 8/27/21 8:17 PM, Alejandro Colomar (man-pages) wrote:
Hi David, On 8/28/21 2:01 AM, Alejandro Colomar (man-pages) wrote:quoted
I mean: !(int)x (int)!x The precedence doesn't matter there, as they apply one after the other, right to left. So, I'll keep casts in row 2.Hmm, I just came up with some very stupid piece of code that can show the different precedence between "unary operators" and "cast operators": sizeof(int)x; Which I hope no-one on earth would ever want to be valid C. If casts had the same precedence as unary operators, this would be: First, cast x to int, then apply sizeof to the resulting int (since sizeof can be used without parentheses on non-types). But since sizeof has greater precedence than the cast, it would be: First, calculate sizeof(int), then... x? Invalid expression! And luckily, the second thing happens, and the compiler yells: sizeof.c: In function ‘foo’: sizeof.c:3:20: error: expected ‘;’ before ‘x’ 3 | return sizeof(int)x; | ^ | ; So I think this deserves a new row. Thanks! Alexquoted
Cheers, Alex
-- Have all good days! David Sletten