public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Pointer woes... (int) 0 or (void *) 0 for NULL???
@ 1998-03-10 17:06 Mark Schaefer
  0 siblings, 0 replies; 4+ messages in thread
From: Mark Schaefer @ 1998-03-10 17:06 UTC (permalink / raw)
  To: egcs

    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
{

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

//  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
returned

 }

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?

Thanks

--
Mark Schaefer



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Pointer woes... (int) 0 or (void *) 0 for NULL???
  1998-03-12 16:29 ` Mark Schaefer
  1998-03-13 18:29   ` Branko Cibej
@ 1998-03-13 18:47   ` Joe Buck
  1 sibling, 0 replies; 4+ messages in thread
From: Joe Buck @ 1998-03-13 18:47 UTC (permalink / raw)
  To: Mark Schaefer; +Cc: egcs

>     Here's the problem as far as I can tell:
> 
>     In the egcs distribution is a set of C++ include files that are by
> default installed into /usr/local/include.  Two files (libio.h, and
> streambuf.h) have the following code:
> 
> #ifndef NULL
> #ifdef __GNUG__
> #define NULL (__null)
> #else
> #define NULL (0)
> #endif
> #endif

__null is a non-standard magic cookie for pointer to unknown object.
It appears that it does not work to try to convert it into a pointer
to member function.

I'm not sure that it really was such a good idea.  I think that the
original thinking was to have something that works like (void *) except
that it can be converted to pointers of other types without a cast in C++,
but still not be mistaken for an integer for purposes of overloading,
or in stdargs functions where sizeof(int) != sizeof(void*).

>     That macro is killing me for some reason.  I keep on getting this
> error:
> cannot convert `0' from type `{unknown type} *' to type `void
> (UiCallbackHandler::*)(_WidgetRec *, void *, void *)'
> 
>     However, I can't seem to reproduce it in a small test case.  It may
> be a clash with X of Motif, but I removed the code above and #defined it
> as 0, and it fixed all my ills.  If there's any real interest, I'll try
> to come up with a testcase.

I've never encountered the bug because I have always followed Stroustrup's
advice and used 0 to represent the null pointer.

But if we are going to provide __null, it seems that we have to decide
what it does when used as a pointer to function or member.  It seems that
it should be accepted as if it were 0.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Pointer woes... (int) 0 or (void *) 0 for NULL???
  1998-03-12 16:29 ` Mark Schaefer
@ 1998-03-13 18:29   ` Branko Cibej
  1998-03-13 18:47   ` Joe Buck
  1 sibling, 0 replies; 4+ messages in thread
From: Branko Cibej @ 1998-03-13 18:29 UTC (permalink / raw)
  To: Mark Schaefer; +Cc: egcs

Mark Schaefer wrote:

>     In the egcs distribution is a set of C++ include files that are by
> default installed into /usr/local/include.  Two files (libio.h, and
> streambuf.h) have the following code:
>
> #ifndef NULL
> #ifdef __GNUG__
> #define NULL (__null)
> #else
> #define NULL (0)
> #endif
> #endif
>
>     That macro is killing me for some reason.  I keep on getting this
> error:
> cannot convert `0' from type `{unknown type} *' to type `void
> (UiCallbackHandler::*)(_WidgetRec *, void *, void *)'

Could this be a bug in egcs' interpretation of __null?

The error message seems to say that you're trying to assign a pointer to a
pointer-to-member; that's not allowed in C++. The meaning of __null in such
a context should not be `{unknown type} *', it should be, e.g., `{unknown
class} ::*'.

--
Branko Cibej   <branko.cibej@hermes.si>
HERMES SoftLab, Litijska 51, 1000 Ljubljana, Slovenia
phone: (++386 61) 186 53 49  fax: (++386 61) 186 52 70



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Pointer woes... (int) 0 or (void *) 0 for NULL???
  1998-03-11  9:31 FW: " Kaz Kylheku
@ 1998-03-12 16:29 ` Mark Schaefer
  1998-03-13 18:29   ` Branko Cibej
  1998-03-13 18:47   ` Joe Buck
  0 siblings, 2 replies; 4+ messages in thread
From: Mark Schaefer @ 1998-03-12 16:29 UTC (permalink / raw)
  To: egcs

    Egcs developers,

    Here's the problem as far as I can tell:

    In the egcs distribution is a set of C++ include files that are by
default installed into /usr/local/include.  Two files (libio.h, and
streambuf.h) have the following code:

#ifndef NULL
#ifdef __GNUG__
#define NULL (__null)
#else
#define NULL (0)
#endif
#endif

    That macro is killing me for some reason.  I keep on getting this
error:
cannot convert `0' from type `{unknown type} *' to type `void
(UiCallbackHandler::*)(_WidgetRec *, void *, void *)'

    However, I can't seem to reproduce it in a small test case.  It may
be a clash with X of Motif, but I removed the code above and #defined it
as 0, and it fixed all my ills.  If there's any real interest, I'll try
to come up with a testcase.

Thanks!! (BTW: This is tons!! better than 2.7.2!)

--
Mark Schaefer




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1998-03-13 18:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-03-10 17:06 Pointer woes... (int) 0 or (void *) 0 for NULL??? Mark Schaefer
1998-03-11  9:31 FW: " Kaz Kylheku
1998-03-12 16:29 ` Mark Schaefer
1998-03-13 18:29   ` Branko Cibej
1998-03-13 18:47   ` Joe Buck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).