This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Compiling GCC with g++: a report
- From: Florian Weimer <fw at deneb dot enyo dot de>
- To: Gabriel Dos Reis <gdr at cs dot tamu dot edu>
- Cc: gcc at gcc dot gnu dot org, jason at redhat dot com, mark at codesourcery dot com, dberlin at dberlin dot org
- Date: Tue, 24 May 2005 09:38:22 +0200
- Subject: Re: Compiling GCC with g++: a report
- References: <m364xapix6.fsf@merlin.cs.tamu.edu>
* Gabriel Dos Reis:
> The first resistance seems to come from the pervasive use of the implicit
> conversion void* -> T*, mostly with storage allocating functions.
This can be worked around on the C++ side, see the example code below.
It's a kludge, but it's not too bad IMHO.
class xmalloc_result;
xmalloc_result xmalloc (size_t);
class xmalloc_result
{
friend xmalloc_result xmalloc (size_t);
const size_t size_;
xmalloc_result (size_t size)
: size_ (size)
{
}
xmalloc_result operator= (const xmalloc_result&);
// not implemented
public:
template <typename T> operator T* () const
{
return static_cast<T*> (malloc(size_));
}
};
inline xmalloc_result
xmalloc (size_t size)
{
return xmalloc_result (size);
}
char *
foo (void)
{
return xmalloc (1);
}
void
bar (int **result)
{
*result = xmalloc (sizeof (int));
}