From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paul Hilfinger To: Eli Zaretskii Cc: dan@cgsoftware.com, gdb@sources.redhat.com Subject: Re: Cast to a struct in expressions Date: Sat, 28 Apr 2001 02:12:00 -0000 Message-id: <200104280912.CAA09949@tully.CS.Berkeley.EDU> References: <8011-Sat28Apr2001110937+0300-eliz@is.elta.co.il> X-SW-Source: 2001-04/msg00210.html > > > I'm still missing something, because I don't see how "*(struct foo *)x" > > > differs from "*(struct {long foo; unsigned bar;} *)x". Both are valid > > > C expression syntax, so the parser should be able to parse them both. > > > > No, they aren't both *expressions*, only one is. > > One is a statement/declaration, and the other is an expression. > > I'm not a C language expert, but my references seem to disagree with > you. Correct; both are expressions, or you couldn't write long z = (*(struct {long foo; unsigned bar;} *)x).foo; whereas, in fact, you can. Of course, the semantics of *(struct {long foo; unsigned bar;} *)x is officially undefined, since, contrary to the fond beliefs of many C programmers, the Standard only occasionally gives meaning to dereferences of a cast of a pointer value to a different pointer type (the anonymous type in the expression above necessarily differs from that of x). Therefore, GDB is not completely out of line in refusing to recognize this, even if the reason it gives is maybe a little off. Paul Hilfinger