Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Daniel Jacobowitz <drow@mvista.com>
To: gdb-patches@sources.redhat.com
Subject: Re: [patch/rfc] Test struct0
Date: Wed, 04 Feb 2004 15:59:00 -0000	[thread overview]
Message-ID: <20040204155907.GA4130@nevyn.them.org> (raw)
In-Reply-To: <40211529.3020504@gnu.org>

On Wed, Feb 04, 2004 at 10:52:09AM -0500, Andrew Cagney wrote:
> >On Tue, Feb 03, 2004 at 07:06:47PM -0500, Andrew Cagney wrote:
> >
> >>Hello,
> >>
> >>This adds a test for:
> >>
> >>	struct foo0 { };
> >>
> >>to the structs.exp testcase (I'm assuming that this is legal ISO-C), it 
> >
> >
> >Nope.
> 
> I guess I misunderstood Jim's comments.
> http://sources.redhat.com/ml/gdb-patches/2004-01/msg00717.html

Hmm, the comment isn't very clear.  Yes, this is a GNU extension
(though not many people seem to know it).

> >      struct-or-union-specifier:
> >           struct-or-union identifier-opt { struct-declaration-list }
> >           struct-or-union identifier
> >
> >      struct-or-union:
> >           struct
> >           union
> >
> >      struct-declaration-list:
> >           struct-declaration
> >           struct-declaration-list struct-declaration
> >
> >      struct-declaration:
> >           specifier-qualifier-list struct-declarator-list ;
> >
> >So there must be a minimum of one declarator and trailing semicolon
> >inside the braces.  GCC will warn about this if you ask it to - it's
> >probably -ansi, or -std=c89 -ansi -pedantic.
> 
> >While it's not legal C, I believe that it is legal C++.
> 
> But are you sure?  :-)  If it's legal C++ then it, along with some other 
> wierd-o edge cases should probably be added to a gdb.cp/struct0 test 
> (someone with less rusty C++ than me can probably come up with a list).
> 
> Trying to include it in structs.exp would just be too messy.

Yeah.  Of course, there's the interesting property that zero-element
structures have non-zero size in C++.  That's because they're a
first-class part of the language.  Consider:

struct foo { };
struct foo bar[10];

int baz = sizeof (bar);

In GNU C, baz is initialized to zero.  In GNU C++ (i386-linux, but I
think all targets since the v3 ABI covers this), baz is initialized to
ten.  One byte per zero-sized struct is wasted in order to preserve
monotonically increasing array element addresses.  Then, in some cases
(all dealing with base classes), the one byte is optimized away again.

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer


  reply	other threads:[~2004-02-04 15:59 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-02-04  0:06 Andrew Cagney
2004-02-04  0:46 ` Daniel Jacobowitz
2004-02-04  1:34   ` Joel Brobecker
2004-02-04 15:52   ` Andrew Cagney
2004-02-04 15:59     ` Daniel Jacobowitz [this message]
2004-02-10 21:07 ` Andrew Cagney

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=20040204155907.GA4130@nevyn.them.org \
    --to=drow@mvista.com \
    --cc=gdb-patches@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