Why would a vararg function parameter work?


Recently I've encountered a problem with a function that accepts variable number of arguments and expects the last one to be a null pointer. I don't have access to its implementation.

Casting that last parameter to a void* worked, but passing in NULL (nullptr not available) directly wouldn't:

foo(x,y,(void*)NULL);   //okay
foo(x,y,NULL);          //crash

IMO this shouldn't make a difference, but then again, I've been wrong before. Can you think of any reason the cast would make a difference? or is this simply an accident (some desync or faulty build or smth. along those lines)

Sorry in advance that I can't provide more details.

Well, NULL is an integral constant in C++, whereas (void *)NULL is very definitely a pointer type.

So they could conceivably have different sizes when inserted into the var-arg list. So this would certainly make a difference if, say, there's another parameter following it. And if there isn't, you may end up reading half-garbage from inside the var-arg function.