public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Gabriel Dos Reis <gdr@cs.tamu.edu>
To: "Giovanni Bajo" <giovannibajo@libero.it>
Cc: "Joseph S. Myers" <jsm28@cam.ac.uk>, <gcc@gcc.gnu.org>
Subject: Re: attribute data structure rewrite
Date: Fri, 24 Sep 2004 04:18:00 -0000	[thread overview]
Message-ID: <m3u0tonznu.fsf@merlin.cs.tamu.edu> (raw)
In-Reply-To: <00cf01c4a1e0$bf25faa0$dc4e2a97@bagio>

"Giovanni Bajo" <giovannibajo@libero.it> writes:

| Gabriel Dos Reis wrote:
| 
| > We used to accept it because we did not implement offsetof correctly.
| > For example, the following variation should be rejected (in C89 an C++
| > mode)
| >
| >    struct A { char foo[10]; };
| >    void bar(void) {
| >      int i;
| >      for (int i = 0; i < 10; ++i)
| >         {
| >            char ary[offsetof(struct A, foo[i] + 1);
| >         }
| >    }
| 
| I don't understand your example because I don't think the +1 there is valid.
| Unless you meant:
| 
| char ary[offsetof(struct A, foo[i])+1];

Yes, this is what I meant.  
Sorry for the typo, and sending a testcase without compiling :-)

| Anyway, what about this in C99? 

Even in strict C99 mode, it will not be valid.  One could think of GNU
extensions that compute offsetof at run-time, but that is something
we've debated much in the past.  I see the move to the new
implementation as a desire to keep away from that.  
RTH might want to weight in.

| We don't need a constant expression in this
| context, and even if offsetof is always a constant expression we could still
| accept it as an extension. 

I agree that in C99, one does not need a constant expression to make
it work, but the offsetof-subexpression still will not be valid.

| In other words, we could transform it to
| offsetof(struct A, foo)+i*sizeof(foo[0]) in contexts that don't require a
| constant expression.

That is a possibility.  I'm not sure how serious the issue is.

-- Gaby

  reply	other threads:[~2004-09-24  2:55 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-09-24  0:15 Geoffrey Keating
2004-09-24  0:34 ` Andrew Pinski
2004-09-24  1:30   ` Joseph S. Myers
2004-09-24  1:47   ` Zack Weinberg
2004-09-24  6:52   ` Geoffrey Keating
2004-09-24  1:40 ` Gabriel Dos Reis
2004-09-24  2:34   ` Giovanni Bajo
2004-09-24  2:59     ` Gabriel Dos Reis
2004-09-24  4:17       ` Giovanni Bajo
2004-09-24  4:18         ` Gabriel Dos Reis [this message]
2004-09-24  8:40     ` Andreas Schwab
2004-09-24  8:40       ` Andreas Schwab
2004-09-24  9:17     ` Joseph S. Myers
2004-09-24 14:45       ` Giovanni Bajo
2004-09-24  8:36   ` Geoffrey Keating
2004-09-24 14:03     ` Joseph S. Myers
2004-09-24  2:35 ` Giovanni Bajo
2004-09-24  8:33   ` Geoffrey Keating
2004-09-24 12:24     ` Nathan Sidwell
2004-09-24 22:29 ` Mark Mitchell

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=m3u0tonznu.fsf@merlin.cs.tamu.edu \
    --to=gdr@cs.tamu.edu \
    --cc=gcc@gcc.gnu.org \
    --cc=giovannibajo@libero.it \
    --cc=jsm28@cam.ac.uk \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).