Re: ?? warning: ANSI C++ forbids implicit conversion from `void *' in initialization ???
- From: Paul Davis <pbd Op Net>
- To: Chris Seberino <seberino spawar navy mil>
- Cc: gtk-list gnome org
- Subject: Re: ?? warning: ANSI C++ forbids implicit conversion from `void *' in initialization ???
- Date: Wed, 13 Feb 2002 17:57:11 -0500
>I looked for NULL explanation about why "= NULL" bad
>but could not anything. Can you give me a 1-2 sentence
>explanation? Is it a security risk somehow or something?
no, not a security problem. consider how you'd define NULL.
#define NULL ((void *)0)
now try to use this:
SomeObject *ptr = NULL;
because C++ is much stricter about types, the compiler will/may
complain that it cannot perform an implicit cast of void * to
SomeObject *. So in fact, the only acceptable definitions of NULL are
0 or 0L or 0UL or 0U, with no type casting. Since the definitions in a
C header file nearly always include the type cast, and since no type
cast is acceptable, using NULL is a bad idea. [ quote from a message i
found with google]:
the C++ standard guarantees that if you use 0 in a pointer context,
it will be converted to whatever that platform uses for the "null
pointer", even if it happens not to have a bit pattern of all
zeroes. (Section 4.10) Therefore, it's safe to use 0 to mean "the
null pointer".
so, just stick to 0.
--p
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]