TITLE: Casting of 0 in variadic functions [ A variatic function is one which is declared to take a variable number of arguments (has an ellipsis in its prototype. -adc ] PROBLEM: magsig@netcom.com (Pete Magsig) [..the standard questions about NULL] I use the classic definition #define NULL 0L and thats it. The "L" may seem overly cautious, but it guarantees that a null pointer is passed as a long to vararg functions that expect "real" pointers. RESPONSE: olaf@cwi.nl (Olaf Weber) Unfortunately, it offers no such guarantees. Since pointer representations don't have to be the same for all types either, you should _always_ cast NULL if used as an "ellipsis argument". RESPONSE: clamage@Eng.Sun.COM (Steve Clamage), 27 Oct 94 Let me expand on Olaf's point. You are not guaranteed that pointers and longs are the same size. Simple example: On x86 in small-memory model, using 0L for NULL will produce the wrong result when passed to a variadic function. A plain 0 would produce the correct result. But recompile using a large-data model and suddenly 0L gives the right result and plain 0 does not. The hacker at this point would say, "Aha! Just #ifdef on the memory model and I'm done." Sorry, no, you just need more #ifdef's as you move the code to different systems. Olaf presented the best solution: Always cast a null to the expected pointer type when passing it to a variadic function: somefunc(p, q, (char*)0); // or (char*)NULL