Does it possible to invoke a procedure via pointer? I haven’t found anything about it on the internet, but the following experimental code compiles without warnings.
#include <iostream>
#include <ctime>
using namespace std;
void PrintCurrentClock()
{
cout<<clock()<<endl;
}
void PrintCurrentTimeStamp()
{
cout<<time(0)<<endl;
}
int main()
{
void* pF = PrintCurrentClock;
pF;
pF = PrintCurrentTimeStamp;
pF;
system("Pause");
return 0;
}
The output is empty, as if the *pF was somewhat “transparent”.
Both C and C++ have function pointers that let you do what you are looking for:
The
voidin parentheses is optional.The reason you did not find anything on the topic is that for historic reasons both functions and procedures in C are called functions (the reason is that there were no
voidin the original language – procedures returnedintby default, and the return value was ignored). C++ inherited this naming convention.