Questions tagged [function-pointers]

1

votes
2

answer
83

Views

C Function Pointer Differences

I have the following C Code: #include int max(int x, int y, int (*compare)(int, int)) { return (*compare)(x,y) ? x : y; } int greater_than(int x, int y) { if(x > y) return 1; else return 0; } int main(void) { printf('%d',max(6,7,greater_than)); } It's just there to test function pointers. But the c...
Nova Shadowflame
0

votes
2

answer
39

Views

How can I use this pointer with pointer to member function

I have typedef for a function pointer: typedef bool(WlanApiWrapper::* (connect_func) )(WLAN_AVAILABLE_NETWORK, const char *, const char *); and have a method that returns a pointer to function: const auto connect_method = map_algorithm_to_method(*network) So I want to call that like that: (*this.*co...
Andriy
1

votes
0

answer
59

Views

Microchip dsPIC33 C30 function pointer size?

The C30 user manual manual states that pointers near and far are 16bits wide. How then does this address the full code memory space which is 24bits wide? I am so confused as I have an assembler function (called from C) returning the program counter (from the stack) where a trap error occurred. I am...
berntd
1

votes
1

answer
241

Views

C - store different callback function adresses in an array

I'm trying to store different callback function addresses in an array. To be able to store function addresses with different signatures, I have defined a union and I use typecasting. This approach seems to work, but it is not very beautiful. Is there a better solution? typedef union { void (*callbac...
user1160713
1

votes
1

answer
43

Views

vector of boost::function not working with _placeholder

I need your help. I tried a lot to find a solution for the problem but failed so far. Idea: Create a vector of 'command tuples' like the following: typedef boost::tuple command_tuple; std::vector commands { boost::make_tuple('command1', boost::bind(&myclass::command1, this)) }; If the string 'comman...
drtyhlpr
1

votes
0

answer
163

Views

gfortran croaks with procedure pointer initially pointing to function with pointer result

I'm trying to set the initial target of procedure pointer in a module as a function within the module. When the result of the target function is a pointer, the code fails to compile with gfortran. Note that it compiles fine with the Intel compiler. I'm using gfortran 6.4.0. If I remove the pointe...
Sriram Swaminarayan
1

votes
5

answer
288

Views

Check if a pointer to function is initialized

How can I check if a pointer to function was initialized? I can check for NULL, but if not null could be garbage, right? I have the following: #include #include typedef struct client_struct { char *name; char *email; void (*print)(struct client_struct *c); } client; void print_client(client *c) {...
ramires.cabral
1

votes
0

answer
76

Views

Vector seemingly changes type dependent on where it's used

EDIT: The solution: I tried to create a pointer on a memberfunction and thought the pointer would contain the required informations about the class. It turned out that it didn't. So Intellisense was absolutely right about the pointer not pointing to an object with the memberfunction but only the me...
Anyfail
1

votes
0

answer
251

Views

Cast function pointer to (void*)

I have a simple question which is breaking my mind. On my solution, I'm working with a DLL that offers me the following function: int RegisterCallback(TCallbackType CallbackType, void *pLLTProfileCallback, void *pUserData); For more information, the parameter pLLTProfileCallback is a function type d...
Citdar
1

votes
1

answer
58

Views

Examples about function pointer and callback function definition

I'm learning about callback function in C++ and have some problems in understanding the initialization of a callback function such as typedef void (CALLBACK *name)(int,int); I think it looks very similar to the declaration of function pointer like this: typedef void (*name)(int,int); I have a simple...
YQ.Wang
1

votes
1

answer
77

Views

Send a function to MPI processes

I am currently writing a runtime system software for distributed systems and then I intend to evaluate some parallel management stuff. I relied my runtime systems on the task programming model as in the OpenMP3.0 standard, but for another category of machines with MPI. To do that, I create some MPI...
Adrien Roussel
1

votes
1

answer
26

Views

C pointer to function with unspecifiable signature

I intend to explain a standard proof of recursion theorem in C, by using factorial as an example. So I have #include typedef unsigned Nat; typedef Nat Func(); Nat G(Nat n, Func f){ if(n) return n * f(n-1, f); else return 1; } int main(void){ printf('%u', G(5, G)); return 0; } It works (prints 120)...
Veky
1

votes
1

answer
18

Views

When calling a member function of a class, I get Error C3867

In my displayData member function of the car class, the error says I should create a pointer to the member, do I have to create pointers to the member? If I do how so? I completely forget pointers. Do i make the object a pointer then point to the displayData member function? I get no red squiggles j...
walshline
1

votes
2

answer
107

Views

How to make sure to avoid branch misprediction when calling a method using one of two methods based on a boolean

Let's say you have a call to a method that calculates a value and returns it : double calculate(const double& someArg); You implement another calculate method that has the same profile as the first one, but works differently : double calculate2(const double& someArg); You want to be able to switch f...
Norgannon
19

votes
3

answer
1.3k

Views

How to call a function with default parameter through a pointer to function that is the return of another function?

I have a function Mult that takes two integers and returns the product of its parameters. And a function Double that takes an integer and returns a pointer to function that returns an integer and takes two integer parameters like Mult. Mult's second parameter is default So when I call Double, Double...
Syfu_H
1

votes
0

answer
60

Views

What is the syntax for setting up and calling a private member function in A from B using a function pointer?

I'm trying to create a callback function that Foo can call to Bar. I run into 'Run-Time Check Failure #0'. I've done some research about this but it hasn't clicked for me, hence my I'm posting this question. I first ran into this problem trying to set up a trigger gameplay system for my hobbyproject...
larssonmartin
1

votes
1

answer
26

Views

How to Call function pointer from other class

let's say I have simple class with some simple function pointer, like that: class ClassWithFuncPointer { public: inline void firstFunction() { /* do something */ }; inline void secondFunction() { /* do something */ }; // MY FUNCTION POINTER void (ClassWithFuncPointer::*funcPointer) (); // AND I CAN...
pajczur
1

votes
6

answer
1.5k

Views

How to assign a member function to an array and call it

I'm currently doing it this way, but seems to not be the proper way: class Name { protected $jobs2do; public function __construct($string) { $this->jobs2do[] = $this->do; } public function do() { ... } } Because directly assign a function will cause warning, should do something like: function func()...
omg
1

votes
3

answer
207

Views

Refactoring function pointers to some form of templating

Bear with me as I dump the following simplified code: (I will describe the problem below.) class CMyClass { ... private: HRESULT ReadAlpha(PROPVARIANT* pPropVariant, SomeLib::Base *b); HRESULT ReadBeta(PROPVARIANT* pPropVariant, SomeLib::Base *b); typedef HRESULT (CMyClass::*ReadSignature)(PROPVARIA...
Stigma
1

votes
1

answer
1k

Views

Boost.Fusion Functional: Calling functions with default arguments

Is it possible to use boost::fusion::invoke function to call a function that has default arguments without specifying those? Example: void foo(int x, int y = 1, int z = 2) { std::cout
Karel Petranek
1

votes
1

answer
417

Views

Adding signal handler to a function in C for a thread library

I am writing a basic user level thread library. The function prototype for thread creation is thr_create (start_func_pointer,arg) { make_context(context_1,start_func) } start_func will be user defined and can change depending on user/program once after creation of thread, if I start executing it us...
cyrux
1

votes
1

answer
68

Views

How can I name an obj-c function to call in xml data

Newbie question here. I'd like to be able to specify through data (i.e. an XML file), the appropriate Objective-C message to send. Any advice on if this is possible or how I can do this? The next best thing, if I can't do this, would be some way to create a map object that would correlate a key (a...
Joey
1

votes
2

answer
1k

Views

passing (function) pointers between c and mono

Hi after refering to http://www.mono-project.com/Embedding_Mono i can call methods from managed code by using mono_runtime_invoke. Now i want to call a method in the managed code with a function pointer (or at least some pointer) as argument from native c code managed code public delegate void MyD...
Gobliins
1

votes
2

answer
3.1k

Views

C++ : Getting function virtual 'address' with member function pointer

This question is similar to Print address of virtual member function I would like to retrieve the memory location of a function (in runtime), using a member function pointer. The goal is to log them, and do a post-mortem analysis, using 'ln' in WinDbg to retrieve which function it was, using PDB sy...
user616959
1

votes
1

answer
121

Views

Function object in object array

I am trying to implement a model in javascript in a object-oriented manner. Say I have object X with bunch of functions. I want to have an object array 'in X' that some of its fields point to some functions in X. Here is the example of what I tried: function X(){ this.open = function(e){...}; this.r...
user804723
1

votes
1

answer
410

Views

Android activity that can receive custom logic from plugins at runtime

I'm trying to write an application that manipulates camera data. I would like to make this framework extensible so that others can write different manipulation logic by implementing a single method with the appropriate signature. What I'm imagining is that the user installs my application plus a few...
Chinasaur
1

votes
2

answer
121

Views

Pointers to functions and derived classes

I'm having a problem with g++ and how templates interact with pointers to functions. Consider the following declaration of a template. template class TestTemplate { private: T* context; public: TestTemplate(T* usingClass); B* testfcnOK(B* arg); B* testfcnBAD(B* (T::*fcn)(void)); }; template TestTe...
Randall Fairman
1

votes
2

answer
991

Views

Bind function pointer to boost::function object

How can I initialize a boost::function object with a raw function pointer? Metacode extern 'C' { class Library { ... }; Library* createLibrary(); } ... void* functionPtr = library.GetFunction('createLibrary'); boost::function functionObj(functionPtr); Library* libInstance = functionObj(); If you...
Mythli
1

votes
1

answer
784

Views

“No matching function for call” with variadic templates

I have a class that is designed to dynamically load a .dll or .so or equivalent. From there, it will return pointers to whatever function you're trying to find. Unfortunately, I've come across two issues in my implementation. If I use the 'dumb' function returning void* as pointers to functions, I g...
mechanarchy
1

votes
1

answer
210

Views

Function-Pointer in Interpreter

I am building a C-Interpreter (in C++) which builds an AST. I want to give the user the opportunity to communicate with real DLLs. For example: I call a function from a DLL. This function expects an pointer to an function (to callback). There is the problem: I don't have a real address to a function...
dcast
1

votes
2

answer
125

Views

Passing object information to cost function

Here is the problem. I use minpack for non-linear optimization. The cost function has the following signature: void cost_function(const int* n, const int* m,const double *p, double *x, int* iflag) n - size of initial point m - size of function vector p - initial point x - function vector I have for...
Alex Hoppus
1

votes
2

answer
367

Views

Returning class pointer, when asked for struct pointer (C++)

I have a skeleton of a project I need to implement a Doubly Linked List (no using stl) and the way the class is implemented is to inherit all is methods from a struct like so: struct IDoubleList { virtual IDoubleNode * getHead() = 0; virtual IDoubleNode * getTail() = 0; virtual void setHead(IDoubl...
Dreken105
1

votes
4

answer
160

Views

Member function to a list of pointer

Thanks for giving comments to the following. Class1 { debug(std::ostream&){} }; int main() { std::vector list1; // some work to do } Target Platform: Platform(1): Win 7x64, VS2010 Platform(2): Linux x32, g++ 4.4 Q: What should be the correct way to pass 'std::cout' to following statement? std::for_e...
YamHon.CHAN
1

votes
1

answer
161

Views

Mixed-Code - Function Member Pointers

I would like to call a FORTRAN function from my C++ code. The FORTRAN function is something like this extern 'C' { void FORTRANFUNC( void FCN(int*,double*), int *N); } The FCN function reported above is a member function of a C++ class class CppClass { ... void FCN(int* a, double* b); ... }; I woul...
alberto.cuoci
1

votes
1

answer
843

Views

Member function & const member function pointer deduction

I have the following code: template class Foo { public: template void foo(T&, const std::function&) { std::cout
ixSci
1

votes
1

answer
88

Views

parent doesn't create child?

I try to create 4 child processes who will work simultaneously, but the output of my program is quite random: sometimes one of the processes is not created (the printf statement is not executed). I can not understand the reason for this, because when I use the wait() function in my parent it should...
Tono
1

votes
1

answer
339

Views

Accessing a member function from another class without prior knowledge of the specific member function

I want to create a class that will access the member functions of a family of classes. Going into more detail, I have class ControlChaos which is declared like this: #define CALL_MEMBER_FN(object, ptrToMember) ((object)->*(ptrToMember)) typedef double (MultiMaps::*mapsGetPtr)(); typedef void (MultiM...
Joey Dumont
1

votes
2

answer
208

Views

C++ regex library with substitution to function pointer [closed]

Looking for something similar to Python's regex sub or subn methods. http://docs.python.org/library/re.html So basically a C/C++ api like this re.sub(pattern, repl, string, count=0, flags=0) Where I can put a function pointer for repl like you can in Python.
1

votes
2

answer
639

Views

Member function pointer for overloaded member function

Note: following code example is not a real code, the real code is far more complicated to paste it here, so the example may seems ridiculous, but it is not important. struct Base { void beginEvent(int a) { impl(a, &Base::onBeginEvent, &Base::onBeginEvent); } void endEvent(int a) { impl(a, &Base::onE...
relaxxx
1

votes
2

answer
503

Views

declare an array of N pointers to functions returning pointers to functions returning pointers to characters

Ugly interview question: How would you declare an array of N pointers to functions returning pointers to functions returning pointers to characters in c++? Show it with and without typedef. Let's say the functions take no params. Is mine correct with typedef? typedef char* (*f1)(); typedef f1 (*f2)(...
user511792

View additional questions