public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Guenther <richard.guenther@gmail.com>
To: "Pedro Lamarão" <pedro.lamarao@ccppbrasil.org>
Cc: gcc@gcc.gnu.org
Subject: Re: [gcc-in-cxx] replacing qsort with std::sort
Date: Wed, 12 Aug 2009 13:12:00 -0000	[thread overview]
Message-ID: <84fc9c000908120146n5058f07dpef15ef1492115ae0@mail.gmail.com> (raw)
In-Reply-To: <15727b460908111703l682ab204l39700c8bfde50577@mail.gmail.com>

On Wed, Aug 12, 2009 at 2:03 AM, Pedro
Lamarão<pedro.lamarao@ccppbrasil.org> wrote:
> I've recently started my contributions to the gcc-in-cxx project, and
> eventually decided on the qsort suggestion because it seems the
> easiest one.
> I've made the change in three places in cp/classes.c; the patch can be
> found here:
>
>   http://code.google.com/p/ccppbrasil/wiki/GccInCxx
>
> Is this the way to go?

Please attach patches in the future.

+bool
+field_decl_less (const tree& x_p, const tree& y_p)
+{

you should be able to use std::bind and functors to avoid that
function.

+#include <algorithm>
+
 #include "config.h"
 #include "system.h"

The includes need to come after config.h and system.h at least.

+static bool
+method_name_less (const tree& m1_p, const tree& m2_p)

see above.

-      qsort (VEC_address (tree, method_vec) + slot, len - slot, sizeof (tree),
-            resort_method_name_cmp);
+      std::sort (VEC_address (tree, method_vec) + slot,
+            VEC_address (tree, method_vec) + len,
+            resort_method_name_less);

this hints at the fact that we want to replace VEC ...

> Some questions occurred to me: in order to support a C and a C++
> compiler at the same time, what "portability" mechanism should be
> used? #ifdef guards to switch between qsort and std::sort on the spot,
> based on __cplusplus? Should a helper function be declared somewhere?

We shouldn't do this kind of patches as long as we need to support
a C compiler.

> Also, std::sort requires a "less" function on reference-tovalue-type,
> so the current foo_cmp functions can't be reused.
> Would a separate patch to introduce foo_less variants be acceptable
> for GCC 4.5 right now?

No, I don't see the need for them.

> Also, is the gcc-in-cxx branch still active? Should my objective be to
> contribute patches to this branch?

I think the branch is dead, but you need to ask Ian.

> On a side note, I've studied vec.h and found it hard to change.
> One reason is because this header is included by the gen*.c stuff,
> which is still being compiled by a C compiler, even when building with
> a C++ compiler is enabled.
> I've considered providing a separate version of vec.h when C++ is
> being used, to avoid infinite #ifdefs.
> Is this a good idea?

See above.

Richard.

> --
>  Pedro Lamarão
>

  reply	other threads:[~2009-08-12  8:46 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-12  9:59 Pedro Lamarão
2009-08-12 13:12 ` Richard Guenther [this message]
2009-08-12 14:33   ` Pedro Lamarão
2009-08-12 13:21 ` Ian Lance Taylor
2009-08-29 11:26 ` Pedro Lamarão
2009-08-29 19:42   ` Magnus Fromreide
2009-08-30 10:37     ` Pedro Lamarão
2009-08-31 16:10       ` Richard Henderson
2009-08-31 16:18         ` Pedro Lamarão
2009-08-31 18:36           ` Richard Henderson
2009-08-31 18:54             ` Richard Guenther
2009-08-31 19:01               ` Richard Henderson
2009-08-31 19:06   ` Pedro Lamarão
2009-09-02  0:24     ` Michael Matz
2009-09-02 12:57       ` Pedro Lamarão

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=84fc9c000908120146n5058f07dpef15ef1492115ae0@mail.gmail.com \
    --to=richard.guenther@gmail.com \
    --cc=gcc@gcc.gnu.org \
    --cc=pedro.lamarao@ccppbrasil.org \
    /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).