What is the scope of "type-name" in a cast expression?

Karl Heuer karl at haddock.ima.isc.com
Wed Aug 9 02:09:09 AEST 1989


In article <1324 at majestix.ida.liu.se> mikpe at majestix.ida.liu.se (Mikael Pettersson) writes:
>What is the scope of the "type-name" in a cast expression?
>My impression is that the scope should be the entire surrounding
>expression (but not any further),

There is no such thing as "expression-scope" in C.  Except for labels (which
have function scope) and things declared within the parmlist of a non-defining
function prototype declaration (which have prototype scope, a very short
scope), each identifier has either block scope or file scope.  In your
examples, the identifiers have block scope.

(Some clarifications: externally-declared static objects have file scope but
internal linkage.  Externally-declared non-static objects have file scope and
external linkage, which used to be called "program scope".  Function
parameters have block scope, the block in question being the outermost block
of the function; this differs from function scope, since parameter identifiers
can be redeclared in an inner block, but label identifiers cannot.)

Reference: 3.1.2.1 pANS.  The same rules (except for prototypes) apply to
pre-ANSI C, but the pANS has the most precise description I've seen.

Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint



More information about the Comp.lang.c mailing list