Hi, > as far as i know the compiler does if(!foo) => if(0==foo) =>if(NULL==foo) at > compile time.
i forgot to say that chapter 6.5.3 (C99) says that the unary operator ! can be applied to a pointer type; that's the reason why it works although on first look it seems to work only if the NULL macro is expanded to 0. > But generally it's not possible to compare a pointer with an integer, because > they the have diffent type and often do not have the same size. On sparc64 > the user-space pointer have 32 bit while the kernel-space pointers have 64 > bit, so on that platform comparing integers with pointers is a bad idea. > Therefore gcc generally produces a warning if he finds such ugly code. > > > >> After all, ain't unary logical operations with pointers illegal? > > A pointer is an object of size sizeof(pointer); there is no reason why not to > apply logical operations with that object. I forgot to say that maybe for some operators (look into the standard) you have to use a union to apply them (to the other member of the union): union foo { type *p_p; char a_c[sizeof(type *)]; }; I If sizeof(int) == sizeof(type *) than you can use int as the second member. I Rolf F.