i did this in msvc 2005.
typedef void (*cleanup_t)(); void func(cleanup_t clean) { cleanup_t(); }
Why does this compile? and not give me a warning? ok, it gave me a unreferenced formal parameter warning but originally i did this when clean was in a class no there was no unreferenced formal parameter when this code gave me problems.
What is cleanup_t(); really doing and what is the point? now for laughs i tried int() and that worked also.
It’s executing a default initializer for the cleanup_t type to create a temporary of that type, and then never actually using that temporary.
It’s a lot like a constructor call, the ‘MyClass()’ part of ‘MyClass c = MyClass();’, except that pointer-to-function types don’t actually have constructors. Of course in my code snippet here, ‘MyClass()’ doesn’t necessarily create a temporary, because it’s an initializer expression. The ‘MyClass()’ in ‘MyClass().some_method();’ is perhaps a closer analogy.
‘int()’ is another way of saying ‘int(0)’, which is another way of saying ‘(int)0’, which is another way of saying ‘0’. Again, it assigns to a temporary, and if that’s the whole statement then the temporary is unused.
If you compile the code in the question with -Wall on GCC, you get a warning ‘statement has no effect’. The code a person doing this might have meant to type, ‘clean();’, wouldn’t produce that warning because of course it would have the effect of calling the function. Yet another reason to switch warnings on, and fix ’em properly 😉