This is the mail archive of the gdb@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Cast to a struct in expressions


> Date: Fri, 27 Apr 2001 15:30:22 -0400
> From: Daniel Berlin <dan@cgsoftware.com>
> >
> > 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.  The "cast-expression" is defined as having the form

   cast-expression:
     unary-expression
     ( type-name ) cast-expression

and "type-name" is syntactically a declaration for a function or an
object of that type with the object identifier omitted.

> 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.

I think I understand the trade-offs and appreciate the problems.  I'm
not saying GDB must support such expressions, but the language
definition seems to say it's an expression, so users might expect them
to be supported.  Perhaps something should be said in the docs.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]