So both following expressions have one operator and one operand?
sizeof(int)
(int)x
Yes.
typename is considered an operand in the firs expressin but not in the
second one?
Yes. (In the second one, the type name is part of the operator.)
This is just a matter of terminology, in this case, as applied to
parsing. Since the terminology is made up by humans, it need not
be entirely consistent, or even make all that much sense, as long
as it lets one human communicate with another.
The way to view this, to make sense out of it, is that the cast
operator is inherently made up of the token sequence '(',
type-name-keyword [%], ')'. Having consumed the type-name by this
point, the only "argument" left to call an "operand" is the value
being cast. The sizeof operator is inherently made up of the
keyword token 'sizeof', and if its operand is a type-name, the
type-name is syntactically required to have outer-level parentheses.
Since the parentheses are (again) consumed by the syntax, the
"argument" that is left, that can be called an "operand", is the
type-name (without, in this case, the parentheses, although it
makes no real difference anyway).
[% In C as originally defined by Dennis Ritchie, "typedef" did not
even exist. So all type names were keywords, which made parsing
C easy. All declarations were instantly obvious, as they always
started with a keyword, and since the total set of keywords was
small, everyone knew all of them at a glance. When typedef was
later added, some time in the late 1970s, the language became much
more complicated syntactically, since typedef identifiers are only
distinguishable from other identifiers by context. For instance,
the C89 -- but not C99 -- code fragment:
void f(x);
can mean either:
- declare f as function taking one argument of type int, and
returning void; or
- declare f as function taking one argument of type x, and
returning void.
The former makes use of C89's "implicit int"; the latter occurs if
and only if "x" is a typedef-name. C99 removes this particular
ambiguity by outlawing "implicit int", but other difficult parsing
situations remain. From the parser's point of view, typedef-ed
identifiers are "just like" keywords, except when they are not.
If one attempts to use a conventional scanner and parser generator
like (f)lex and (b)yacc, one must invent clever feedback and/or
feed-forward mechanisms by which the parser can tell the lexer
whether to claim a potential typedef name is a "type name" or an
"identifier name". (Or one could use a more powerful parsing
technique, but that means abandoning yacc.)
Because it is impossible to tell at a glance whether some identifier
is actually a typedef-name, C programmers often find themselves
using some sort of self-imposed (or company coding standard imposed)
typographic convention to "mark" all typedefs. For instance, some
people use _t suffixes, so that it is clear that greeble_t is a
type-name. Others use an initial capital letter, or all-uppercase.]