From mboxrd@z Thu Jan 1 00:00:00 1970 From: Daniel Berlin To: Eli Zaretskii Cc: gdb@sources.redhat.com Subject: Re: Cast to a struct in expressions Date: Fri, 27 Apr 2001 12:30:00 -0000 Message-id: <168339.988385422@dynamic-addr-83-177.resnet.rochester.edu> References: <8011-Fri27Apr2001111107+0300-eliz@is.elta.co.il> <6137-Fri27Apr2001204221+0300-eliz@is.elta.co.il> X-SW-Source: 2001-04/msg00203.html --On Friday, April 27, 2001 8:42 PM +0300 Eli Zaretskii wrote: >> From: Daniel Berlin >> Date: 27 Apr 2001 11:23:55 -0400 >> >> > A parse error in expression, near `long foo; unsigned bar} *)foobar >> > >> > Seems like the parser chokes on the struct declaration? >> Yes. >> > Am I missing something? >> Yes, I think. The parser only handles expressions, nothing more. >> This is why it's c-exp.y, and not c.y. >> :) >> >> If you have a real struct already defined, of course, and di >> >> p/x *(sturct foostruct *)foobar >> >> then *that* should work. > > No, there's no such struct, otherwise I wouldn't be opting for this > complication ;-) > > 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 guess someone just stopped short of making this part of the parser, > because it looks like "struct " is the only syntax it accepts. > Right? No. It's done on purpose. We aren't supposed to be handling statements and declarations, only expressions. Doing more would require making the C parser into a mini-C compiler. You'd have to start injecting types into the symbol table and whatnot. > > Anyway, thanks for the feedback. NP.