public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* FW: Pointer woes... (int) 0 or (void *) 0 for NULL???
@ 1998-03-11  9:31 Kaz Kylheku
  1998-03-12 16:29 ` Mark Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Kaz Kylheku @ 1998-03-11  9:31 UTC (permalink / raw)
  To: 'egcs@cygnus.com'

On Tuesday, March 10, 1998 4:24 PM, Mark Schaefer [SMTP:mschaefer@dsai.com] 
wrote:

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

It really sounds like NULL has not been defined as 0 even though you
think it has.

Repeat your tests with 0 substituded for NULL. Also, in the functions
where the problesms arise, add a diagnostic like:

	cout << "NULL is defined as " << STR(NULL) << endl;


Prior to this, add the following #define's somewhere:

	#define XSTR(X) #X
	#define STR(X) XSTR(X)

This ensures that STR(NULL) turns into a string literal containing
the replacement tokens for NULL.


Remember, in C and C++, you trigger undefined behavior if you
redefine a macro without #undef'ing it first! So if a NULL already
exists and you redefine it, anything may happen, including the
possibility that the old version prevails.

You may only redefine macros if you redefine them with the
exact same replacement text (including same whitespace
separation).


^ 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: Pointer woes... (int) 0 or (void *) 0 for NULL??? 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

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

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-11  9:31 FW: Pointer woes... (int) 0 or (void *) 0 for NULL??? 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).