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

david.f.prosser dfp at cbnewsl.ATT.COM
Wed Aug 9 04:41:10 AEST 1989


In article <1324 at majestix.ida.liu.se> mikpe at majestix.ida.liu.se (Mikael Pettersson) writes:
>I have a question for those who know the details about C declarations:
>
>  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), but the compilers I've tried
>[PCC and GCC on a Sun3] both in fact make the type visible from
>the enclosing statement and downwards to the end of the {}-block.

These compilers are correct w.r.t. the ANSI C draft.  Section 3.1.2.1:

	  Structure, union, and enumeration tags have scope that begins just
	after the appearance of the tag in a type specifier that declares
	the tag.  Each enumeration constant has scope that begins just after
	the appearance of its defining enumerator in an enumerator list.
	Any other identifier has scope that begins just after the completion
	of its declarator.

In this same section, the location where scope ends is specified.  For
file scope, it ends at the end of the translation unit; for block scope,
the } that ends the associate block; for function prototype scope, the
end of the associated function declarator; and for function scope (labels),
the } that ends the function.

There is no such thing as "expression scope".

Dave Prosser	...not an official X3J11 answer...



More information about the Comp.lang.c mailing list