A
Adrian
Can anything bad happen by using a function pointer to a static
function in a different module?
Below is an example:
//FILE: main.cpp
#include <iostream>
typedef int(*func_ptr)(void);
func_ptr func();
int main(int argc, char *argv[])
{
func_ptr x=func();
int y=x();
std::cout << "y=" << y << std::endl;
return 0;
}
// FILE: func.cpp
static int func2(void);
typedef int(*func_ptr)(void);
func_ptr func()
{
return &func2;
}
static int func2(void)
{
// return some random int from mem;
int a;
int b;
return (a+b)*723;
}
function in a different module?
Below is an example:
//FILE: main.cpp
#include <iostream>
typedef int(*func_ptr)(void);
func_ptr func();
int main(int argc, char *argv[])
{
func_ptr x=func();
int y=x();
std::cout << "y=" << y << std::endl;
return 0;
}
// FILE: func.cpp
static int func2(void);
typedef int(*func_ptr)(void);
func_ptr func()
{
return &func2;
}
static int func2(void)
{
// return some random int from mem;
int a;
int b;
return (a+b)*723;
}