This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [RFC] Fixes to bootstrap from a C++ compiler (part 1)
- From: kaih at khms dot westfalen dot de (Kai Henningsen)
- To: gcc-patches at gcc dot gnu dot org
- Date: 25 Jun 2004 22:48:00 +0200
- Subject: Re: [RFC] Fixes to bootstrap from a C++ compiler (part 1)
- Comment: Unsolicited commercial mail will incur an US$100 handling fee per received mail.
- Organization: Organisation? Me?! Are you kidding?
- References: <200406250544.i5P5i8D20776@tin.geop.uc.edu> <40DC4BB9.6000600@codesourcery.com> <32890.::ffff:128.194.146.36.1088191675.squirrel@webmail.nerim.net> <32890.::ffff:128.194.146.36.1088191675.squirrel@webmail.nerim.net> <20040625192940.GA5731@n
drow@false.org (Daniel Jacobowitz) wrote on 25.06.04 in <20040625192940.GA5731@nevyn.them.org>:
> In C++, you have new and delete, which have "magic" behavior in this
> area. When you use other memory allocators, the collection of
> otherwise unnecessary casts gets a bit old.
Wasn't there a proposal to do a macro-supported C version of new/delete? I
seem to recall several different variants being discussed.
Assuming just C90, one of many options would be (leaving out do{}while(0)
and other stuff like that to avoid line wraps):
#define NEW(var, type, count) var = (type *)xmalloc(sizeof(type) * count)
#define DELETE(var) free(var); var = NULL
As a matter of coding style, I might suggest to use some such construct
for everything that would otherwise need a direct cast from (void*). Makes
it easy to find those places (and, for example, change to use a C++ idiom
if the switch to C++ actually happens).
MfG Kai