- Aug 14, 2001
- 12,343
- 0
- 0
I'm using gtkmm's Glib::Module class, which on unix, is just a fancy wrapper around dlopen(), dlsym(), etc. Just like the dl* functions, it takes your void pointer and points it at the symbol you ask for. Well, I want to cast that back to the right function pointer type, but I can't seem to do it without using C-style casts, which everyone boos and hisses at in C++. I tried reinterpret_cast, but it told me that it can't convert between pointer-to-object and pointer-to-function. So this cast is the last non-c-plus-plussy thing left I have in my test code. Here is what I have so far:
// g++ `pkg-config glibmm-2.0 --cflags --libs` GlibModule-test.cc
#include <functional>
#include <glibmm/module.h>
#include <iostream>
using namespace std;
int main() {
Glib::Module mod("libm.so");
typedef double (*double_double_func_t)(double);
void * v = NULL;
mod.get_symbol("cos", v);
pointer_to_unary_function<double, double> cosine((double_double_func_t)v);
double test = 1.234;
cerr << "test is: " << test << endl;
cerr << "cos(test) returned: " << cosine(test) << endl;
}
// g++ `pkg-config glibmm-2.0 --cflags --libs` GlibModule-test.cc
#include <functional>
#include <glibmm/module.h>
#include <iostream>
using namespace std;
int main() {
Glib::Module mod("libm.so");
typedef double (*double_double_func_t)(double);
void * v = NULL;
mod.get_symbol("cos", v);
pointer_to_unary_function<double, double> cosine((double_double_func_t)v);
double test = 1.234;
cerr << "test is: " << test << endl;
cerr << "cos(test) returned: " << cosine(test) << endl;
}