2 ms·
But when would that be needed? The argument is optional, and null is its default value. But the way the overloads are collapsed into a single function, there h
by kazinator 7y ago
But when would that be needed? The argument is optional, and null is its default value.
But the way the overloads are collapsed into a single function, there has to be a run-time check for that null.
Using a null to indicate "argument is not there" is a C API trick. That parameter won't be optional in C.
- kragen 7y agoIf you only have a K&R-style declaration visible, you can still call it with the wrong number of arguments, but (contrary to what you'd expect from doing the same thing in JS or Lua) most C implementations will instead pass some garbage data as the additional parameter, rather than NULL. Also, most C implementations will allow you to cast function pointers in a way that results in calling the function with the wrong number of arguments. If you're especially unlucky, that garbage data will happen to be NULL at first, but then become non-NULL when you recompile with debugging turned off, resulting in truly fascinating ways to spend your Friday and Saturday nights the month before shipping. (I know you know this, Kaz. I'm mentioning this for the benefit of those who haven't yet spent their Friday and Saturday nights this way.)