Re: Error in 'man operator'

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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:
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!

Alex


Cheers,

Alex



--
Have all good days!
David Sletten




[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux