public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: Neil Booth <neil@daikokuya.co.uk>
Cc: nathan@cs.bris.ac.uk, Mark Mitchell <mark@codesourcery.com>,
	gcc@gcc.gnu.org, nathan@codesourcery.com, gdr@codesourcery.com
Subject: Re: Variable-sized types vs. templates
Date: Tue, 08 Oct 2002 07:07:00 -0000	[thread overview]
Message-ID: <wvld6qlgkrh.fsf@prospero.cambridge.redhat.com> (raw)
In-Reply-To: <20021008123541.GA1691@daikokuya.co.uk> (Neil Booth's message of "Tue, 8 Oct 2002 13:35:41 +0100")

On Tue, 8 Oct 2002 13:35:41 +0100, Neil Booth <neil@daikokuya.co.uk> wrote:

> Jason Merrill wrote:-
>
>> Similarly, I think it's appropriate to say that neither VLA nor VM types
>> are valid template type arguments.  I'd also say that a VLA is not a valid
>> type for a struct member; I don't understand why C99 seems to allow that.
>> Perhaps it wants to allow it so that uses in different functions can have
>> different sizes, but that seems incompatible with the stronger C++ model of
>> struct types.

> I think they wanted to formalize hacks like:
>
> /* Chained list of answers to an assertion.  */
> struct answer
> {
>   struct answer *next;
>   unsigned int count;
>   cpp_token first[1];
> };
>
> Where first is an array of size determined at run time.

But first isn't a VLA.  To actually use a VLA in a struct would mean an
example like

  int foo_length;
  struct foo
  {
    int arr[foo_length];
  };

  void f ()
  {
    foo_length = 42;
    {
      foo bar;
      bar.arr[12] = 24;
    }
  }

which seems rather more ugly than the 'struct hack' you refer to.  And,
since it can only be used for local variables, rather useless.  Now that I
think of it, this is probably more what they had in mind:

  void f (int n)
  {
    struct foo { ...; int arr[n]; } bar;
  }

So, to refine my earlier suggestion, in C++ I'd prohibit VLAs in types with
linkage.  A local class such as this is already an invalid template type
parm.

Jason

  reply	other threads:[~2002-10-08 12:47 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-10-08  1:45 Mark Mitchell
2002-10-08  5:35 ` Nathan Sidwell
2002-10-08  6:18   ` Jason Merrill
2002-10-08  6:22     ` Neil Booth
2002-10-08  7:07       ` Jason Merrill [this message]
2002-10-08  7:28         ` Richard Earnshaw
2002-10-08  7:31           ` Jason Merrill
2002-10-08  9:12             ` Richard Earnshaw
2002-10-11  3:20               ` Jason Merrill
2002-10-08  9:04       ` Andreas Schwab
2002-10-08 10:31 ` Jim Wilson
2002-10-08 10:59   ` Richard Earnshaw
2002-10-08 11:09   ` Jim Wilson

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=wvld6qlgkrh.fsf@prospero.cambridge.redhat.com \
    --to=jason@redhat.com \
    --cc=gcc@gcc.gnu.org \
    --cc=gdr@codesourcery.com \
    --cc=mark@codesourcery.com \
    --cc=nathan@codesourcery.com \
    --cc=nathan@cs.bris.ac.uk \
    --cc=neil@daikokuya.co.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).