Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!cbnewsj!asd From: asd@cbnewsj.att.com (Adam S. Denton) Newsgroups: comp.lang.c Subject: Do nil pointers convert to nil pointers? Message-ID: <1991Mar19.234219.22867@cbnewsj.att.com> Date: 19 Mar 91 23:42:19 GMT Organization: AT&T Lines: 35 Let's say I have a "generic" function that might work on different data types. This function might look like this: void generic_func(void *objectp, size_t size); The intended call would be like this: T *x; /* T is some type */ ... generic_func( (void *)x, sizeof(T) ); /* cast included for clarity */ ... Now, suppose generic_func() can be called with a nil pointer; i.e., x can be NULL (make that (T *)0). For this to be useful, generic_func would have some code such as ... /* Note, the following comparison compares "void *"s, not "T *"s!!! */ if (objectp == NULL) {...}; ... When generic_func is called, the nil (T *) argument x will be converted to (void *) before generic_func gets it. My question is, is this guaranteed to produce a *nil* generic pointer, or not? In other words, does ANSI guarantee that (void *)0 compares equal to (void *)(T *)0, or is this just wishful thinking on my part? On a related note, can anything be said for (T1 *)0 vs. (T1 *)(T2 *)0? (Not that converting arbitrary pointers is an acceptable practice... :-)) Thanks in advance, Adam Denton asd@mtqua.att.com