Re: Get gchar* from Glib::ustring



On Wed, 03 Jun 2009 23:53:09 +0200
Daniel Elstner <daniel kitta googlemail com> wrote:
> Am Mittwoch, den 03.06.2009, 22:18 +0100 schrieb Chris Vine:
> 
> > And note that because the argument is untyped (it is an elipsis
> > argument) you cannot use the normal C++ 0 as a synonym for NULL.
> 
> Note that in a C++ context, NULL is usually
> 
> #define NULL 0
> or
> #define NULL 0L
> 
> The latter works on most 64 bit machines as a varargs sentinel, but
> only by accident.  It is not guaranteed by the C or C++ standard.
> 
> > You must either use NULL explicitly or, if you want something more
> > C++ like, cast to void* with static_cast<void*>(0).  Otherwise on
> > 64 bit systems the 0 will be treated as a 32 bit integer rather
> > than a 64 bit pointer.
> 
> An explicit cast of 0 to pointer type is in fact the only safe way.

Good point.  I think on all C platforms supported by glib it is going
to be defined as (void*)0 in practice (it is documented as being the
sentinel in glib documentation), but it isn't required to by any
standard and usually will not be in C++ environments.

Chris



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]