Is "(int)" in "sizeof (int)" a type operator or some special case parameter? [FROM]

I've always assumed that a C expression sizeof (int)

works like a function, with everything inside the parentheses being passed as a parameter. Since int

(or any other type specifier) ​​is actually a keyword and not an object that can be passed around, I assumed it was just some kind of special case hard-coded into the compilers.

But I recently discovered that if I use sizeof

for a variable, I can omit the parentheses ( sizeof var

) and it will compile and work fine. Since sizeof

it is actually the operator itself, not a function (and the operators don't need parentheses) and the type specifiers are the only things that need the parentheses, now I'm wondering if they are really type specifiers, re is actually the type of operators -operators, which are somehow used sizeof

to find sizes for matching types.

+3


source to share


1 answer


()

used with an operator sizeof

if the operand is a data type.

C11: 6.5.3.4 (p2):



An operator sizeof

gives the size (in bytes) of its operand, which can be an expression or a name in parentheses of the type . The size is determined by the type of the operand.

+3


source







All Articles