Quote:
Originally Posted by
ongoto
I meant no offense.
I'm just going along with what you said. The questions you raised supports the fact that it doesn't make any sense, right?
if (exp()) is asking if the function exists; it's not calling that function.
...
The more I think about it, the less sure I am about that. As K&R C treats pretty much all functions as variable-argument, how could the compiler know what you meant? There's no way for a compiler to know if you're doing an existence check which would simply evaluate to the address of the function, or call the function with zero arguments.
I think there's a good chance that code that you identified actually does make the call to exp(), with unknown data on the stack. I think to just check if the function exists, the code would be
if ( exp ).
Either way, anyone who writes code like that without comments on WHAT is being done is being incompetent, in my opinion.
When you go out into the esoteric edges of a programming language like that, even you are likely to not remember exactly what you did later on. And everyone else who didn't write the code is almost certainly going to be stumped for a good bit. Production or library code is not the place to compete in obscure coding ego wars.
And I freely admit that calling a vararg function with zero arguments makes no sense - with undefined junk on the stack, there's no way to know what would happen. That's another reason the code should be commented. To figure out what exactly is going on requires breaking out the C standard and maybe even hardware-specific behavior because "putting variables on the stack" is highly hardware-specific.