This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFC] Fixes to bootstrap from a C++ compiler (part 1)


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]