From: Daniel Berlin <dan@www.cgsoftware.com>
To: <Hilfinger@cs.berkeley.edu>
Cc: Eli Zaretskii <eliz@is.elta.co.il>, <gdb@sources.redhat.com>
Subject: Re: Cast to a struct in expressions
Date: Sat, 28 Apr 2001 11:30:00 -0000 [thread overview]
Message-ID: <Pine.LNX.4.33.0104281421250.19482-100000@www.cgsoftware.com> (raw)
In-Reply-To: <200104280912.CAA09949@tully.CS.Berkeley.EDU>
On Sat, 28 Apr 2001, Paul Hilfinger wrote:
>
> > > > 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;
Except, I tried to compile this with a few c compilers, and it didn't
work.
Only gcc seems to accept it.
>
> 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.
not "completely" out of line?
It's not a c compiler.
It doesn't pretend to be.
I can't even get a lot of c compilers to recognize the expression.
how could gdb be in any way out of line in refusing it, considering it's
just a debugger?
C also says that
given
int a[5];
4[a] == a[4]
We don't allow you to type "print 4[a] = 3", but we do allow "print a[4] =
3".
Is this out of line?
> Paul Hilfinger
>
next prev parent reply other threads:[~2001-04-28 11:30 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-04-27 1:10 Eli Zaretskii
2001-04-27 8:24 ` Daniel Berlin
2001-04-27 10:41 ` Eli Zaretskii
2001-04-27 12:30 ` Daniel Berlin
2001-04-28 1:08 ` Eli Zaretskii
2001-04-28 2:12 ` Paul Hilfinger
2001-04-28 11:30 ` Daniel Berlin [this message]
2001-04-28 11:09 ` Daniel Berlin
2001-04-28 23:47 ` Eli Zaretskii
2001-04-28 23:52 ` Daniel Berlin
2001-04-29 0:20 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.4.33.0104281421250.19482-100000@www.cgsoftware.com \
--to=dan@www.cgsoftware.com \
--cc=Hilfinger@cs.berkeley.edu \
--cc=eliz@is.elta.co.il \
--cc=gdb@sources.redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox