Re: using literal zero for NULL



On 21/03/06 11:09, mikecorn wrote:

>I see your point about the arg-list-end flag.
>
>It seems it should be OK to use a zero in place of NULL when the argument is
>of a type known to the compiler and NULL is a documented way to denote a
>missing argument (e.g. optional window title string). Agree?
>
>Thanks for the response.
>  
>
A literal "0" is interpreted as an int according to the C standard.  If
you are calling a function that expects a pointer, pass a pointer.

You can track down a lot of these problems by turning on warnings in
gcc, and fixing the problems it reports.  If you rely on implicit
pointer <-> integer conversions, you will often run into portability
problems at some point.

The other thing to watch when writing 64-bit safe code is to make sure
you have prototypes defined for all functions you call
(-Wmissing-prototypes can help here).  If you have a function like:
    char *do_something(void) { ... }

And call it from another file without a prototype, the return value from
the implicit prototype will be an int, which results in the pointer
value being truncated.

Note however that this discussion is not really suited for
gtk-devel-list.  If you have further questions, it would be better to
ask them on a C programming list or maybe gtk-app-devel-list.

James.




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