This is the mail archive of the 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]

Pointer woes... (int) 0 or (void *) 0 for NULL???

    Egcs Team,

    I'm trying to port a pretty sophisticated app over to Linux and
discovered a paradox.  You can't use either definition of NULL.  If you
use  #define  NULL (void *) 0  then the following function would return
an error:

char *

If I #define NULL 0 (according to C++ Programming Language, Third
Edition (Bjarne) 5.1.1, this is _almost_ the best way to do it) I get
two types of errors:

void myFunc()
char tmp;
char *test = &tmp;
if (tmp == NULL)  // Yes, this is a bad example
"-- ANSI C++ forbids comparison between pointer and integer "  -- on
line above

            (message, p_view.getViewerPtr()->getShellWidget(),
             UiMessageBox::info, this, NULL, NULL, NULL, NULL,

//  One of the NULL parameters is a pointer-to-function used to create a
Motif message box without any callbacks (to the box that creates it)

"cannot convert `0' from type `{unknown type} *' to type `void
(UiCallbackHandler::*)(_WidgetRec *, void *, void *)" -- is the error


The other side:

char *myFunc2()
    return NULL;
"ANSI C++ forbids implicit conversion from `void *' in return"

Seems like a real catch-22 to me, except that case 1 is written to the
standard that
" Because of standard conversions, 0 can be used as a constant of any
integral, floating-point, pointer, or pointer-to-member type."

Any help on this one?


Mark Schaefer

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