Re: Why is cast from NULL illegal?



On 18 Nov 2002 14:55:43 -0600
Lars Clausen <lrclause cs uiuc edu> wrote:

> 
> After changing Dia's code to have more static type checking, I'm getting a
> number of errors about invalid casts from NULL.  But surely NULL can be any
> type, so any cast of it should be valid.

Hi Lars,
You don't mention what version of GTK you're using, or what language (C, 
C++, etc, but I didn't think Dia used C++...), but I'm reminded of a problem
I had when using GTK 1.2.x with C++.

In that version, the GTK header file glib.h declared NULL itself to be
      #define  NULL    ((void*) 0)
thereby giving it a type.  This caused numerous problems in C++, as void*
cannot be converted to a different type without a cast (Which sounds like
the problem you are describing...)

Anyway, my fix was to ensure that I #included <stddef.h> before any gtk
header files.  This way, the type-less definition of NULL is pulled in
first
        #define NULL 0

I believe this was fixed in GTK2 (Check the archive for a previous
discussion about this...)

Hope this helps!
Ian



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