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

Mikael Pettersson mikpe at majestix.ida.liu.se
Tue Aug 8 11:04:00 AEST 1989


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.

Example of code I think should be rejected:
--huh.c--
/* accepted by PCC and GCC */
f() {
    int i;
    *(enum { foo, bar, bletch } *)&i = bar;
    i = foo;					/* ?? */
}
g() {
    int ia[2];
    ((struct foo { int i,j; } *)ia)->i = 99;
    ia[1] = sizeof (struct foo);		/* ?? */
}
--

AdvTHANX for any references to the appropriate "chapter and verse".

[RTFM? I have looked in both "The C Programming Language - Reference
Manual" (UNIX PS1 4.3BSD) (essentially a reprint from K&R1) and
"C: A Reference Manual, 2nd Ed." (Harbison&Steele) and found nil :-(]
-- 
Mikael Pettersson, Dept of Comp & Info Sci, University of Linkoping, Sweden
email: mpe at ida.liu.se  or  ..!{mcvax,munnari,uunet}!enea!liuida!mpe



More information about the Comp.lang.c mailing list