This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [cxx-conversion] Convert vec.[ch] to C++ [1/3] (issue6233044)
- From: Gabriel Dos Reis <gdr at integrable-solutions dot net>
- To: Tom Tromey <tromey at redhat dot com>
- Cc: Diego Novillo <dnovillo at google dot com>, crowl at google dot com, iant at google dot com, gcc-patches at gcc dot gnu dot org
- Date: Fri, 25 May 2012 13:34:34 -0500
- Subject: Re: [cxx-conversion] Convert vec.[ch] to C++ [1/3] (issue6233044)
- References: <20120523194842.6D6291020B8@torture.tor.corp.google.com> <87d35s5d6a.fsf@fleche.redhat.com>
On Fri, May 25, 2012 at 1:27 PM, Tom Tromey <tromey@redhat.com> wrote:
>>>>>> "Diego" == Diego Novillo <dnovillo@google.com> writes:
>
> Diego> +struct GTY(()) vec_prefix
> Diego> +{
> Diego> + ?unsigned num;
> Diego> + ?unsigned alloc;
> Diego> +};
> Diego> +
> Diego> +/* Vector type, user visible. ?*/
> Diego> +template<typename T>
> Diego> +struct GTY(()) vec_t
> Diego> +{
> Diego> + ?vec_prefix prefix;
> Diego> + ?T GTY((length ("%h.prefix.num"))) vec[1];
> Diego> +};
>
> I'm curious why you didn't use inheritance here.
>
> ? ?template<typename T>
> ? ?struct GTY(()) vec_t : public vec_prefix
> ? ?{
> ? ?...
> ? ?};
Very good question.
I thought about it, and then offered myself "ah, so that vec_t<int> is still
a POD type", allowing some of the usual "C" practices, whereas
inheritance would have ruled that out as C++03 portable code.
-- Gaby