Re: ?? warning: ANSI C++ forbids implicit conversion from `void *' in initialization ???

>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. 


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