Path: utzoo!utgpu!watmath!att!cbnewsl!dfp From: dfp@cbnewsl.ATT.COM (david.f.prosser) Newsgroups: comp.lang.c Subject: Re: What is the scope of "type-name" in a cast expression? Message-ID: <1415@cbnewsl.ATT.COM> Date: 8 Aug 89 18:41:10 GMT References: <1324@majestix.ida.liu.se> Reply-To: dfp@cbnewsl.ATT.COM (david.f.prosser) Organization: AT&T Bell Laboratories Lines: 28 In article <1324@majestix.ida.liu.se> mikpe@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...