function-pointers

Function pointer in parameter

Hi! I need to make a function which adds a function pointer to map. It would be something like this: bool RegisterFunction (string name, FunctionPointer function). But I have problem with calling it, because I don't know how to pass function to it instead of result of function (when I call this as here: RegisterFunction ("run", Run()...

Typedef a container of function pointers

Simple question; right now I have something like this: typedef void(*MyFunctionPointer)(int); typedef std::vector < MyFunctionPointer > MyFunctionPointerContainer; However, I want to typedef this container in one row, skipping the first typedef, how can I do this? ...

Can we say "passing a function pointer as an argument to a function is called as callback function"?

Can we say "passing a function pointer as an argument to a function is called as callback function"? ...

How Callback functions are usefull while building and DLL

Are callback functions equivelent to events in C#(.NET). What I understand about callback function is, it is a function that is called by a reference to that Function. Example Code will be: void cbfunc() { printf("called"); } int main () { void (*callback)(void); callback=(void *)cbfunc; callback(); re...

Any tips for dealing with a very small stack?

I was wondering if any developers in the embedded space know of any interesting tricks to help lessen the pain of developing for microcontrollers with very limited stack space. I've recently been writing some firmware for 8-bit uCs (Microchip PIC18F family, 31 byte stack) and as a consequence I have had to flatten my programs and reduce...

Boost.Python function pointers as class constructor argument

I have a C++ class that requires a function pointer in it's constructor (float(*myfunction)(vector<float>*)) I've already exposed some function pointers to Python. The ideal way to use this class is something like this: import mymodule mymodule.some_class(mymodule.some_function) So I tell Boost about this class like so: class_<Some...

address of c++ template function

Why does this fail to compile? (g++-4.5) template < typename U > static void h () { } int main () { auto p = &h<int>; // error: p has incomplete type } EDIT: Here is a work-around: template < typename U > static void h () { } int main () { typedef decltype (&h<int>) D; D p = &h<int>; // works } ...

Arbitrary pointer to unknown class function - invalid type conversion

I have a hack program; it injects some functions into a target process to control it. The program is written in C++ with inline assembly. class GameProcMain { // this just a class }; GameProcMain* mainproc; // there is no problem I can do =(GameProcMain*)0xC1EA90 Now I want to define a class function (which set ecx to class pointer)...

Assigning a value to a non-static function pointer resulting in crash - WHY?

I have a function which is defined like this: typedef void (*logprintf_t)(const char* format, ...); logprintf_t logprintf void my_function() { logprintf = cast(logprintf_t)0x12345; } and it causes the application to exit. However, if I make the logprintf be static (I've seen this trick somewhere), i.e.: void my_function() { s...

Defining a delegate as a function pointer

I am using a delegate which calls an unmanaged function pointer. This causes the Garbage Collector to collect it before it is used, as described in the CallbackOnCollectedDelegate MDA page on MSDN: MSDN page for CallbackOnCollectedDelegate MDA. The resolution states that I have to marshal the appropriate delegate as an unmanaged functio...

Function Pointers in VS-2010 ( + Virtual Alloc call)

Hi everyone, As an experiment i am trying to write the following program which allows me to generate code during runtime. i.e. i do the following: 1. Fill a buffer with op-codes of the instructions i want to execute. 2. Declare a function-pointer and make it point to the start of the buffer. 3. Call the function using the above func-pt...

[C2664] cannot convert parameter 1 from 'overloaded-function' to '...'

Now I am try to use boost bind & mem_fn. But there's a problem to bind overloaded-function. How to resolve compile error of follow codes? boost::function< void( IF_MAP::iterator ) > bmf = std::mem_fun1< void, IF_MAP, IF_MAP::iterator >( &IF_MAP::erase ); boost::function< void( IF_MAP::iterator ) > bmf = boost::mem_fn< void, IF_MAP, IF_M...

in which segment of the program are function pointers stored?

Hi, I wanted to know in which section of the program are function pointers stored? As in, is it on the program stack or is there a separate section for the same? void f(void){} int main(void){ int x[10]; void (*fp)(void) = NULL; fp = f; return 0; } Now, will the address of x and fp be in the same segment of the program's stack me...

how to make pointer to non-member-function?

if i have for example class A which contains the functions: //this is in A.h friend const A operator+ (const A& a,const A& b); friend const A operator* (const A& a,const A& b); which is a global (for my understanding). this function implemented in A.cpp. now, i have class B which also contains the functions, and the member: //this ...

function pointers error C2373: redefinition; different type modifiers

Hi there, I'm trying to compile some function pointers assignment code. I tried different variations of pointer assignments and __cdecl as well. But without success, after a while I gave up... maybe you'll see something what i can not. I compile with visual express 2008, with flags: /Gd __cdecl calling convention /O2 maximiz...

pointer to function

Hi , i have template class that I did , and i want to do pointer to function: #ifndef __DATABASE_H_ #define __DATABASE_H_ #pragma once #include "Heap.h" #include <string> #include <map> #include <iostream> using namespace std; template<class S,class T> class Database { public: bool IsEmpty() const { return (m_map.size() == 0); }...

function pointer without typedef

Is it posible to use the type of a prefiously declared function as a function pointer without using a typedef? function declaration: int myfunc(float); use the function declaration by some syntax as function pointer myfunc* ptrWithSameTypeAsMyFunc = 0; ...

passing functions

Ok, it's been a while since I wrote in C++. and I've never done anything quiet this high level. So basically I need to create a class. The constructor for the class needs to take a reference (or pointer) to a method form another class, or to a function. Basically I have a class that needs to on occasion read a value from a fltk valuato...

calling native function pointer in c++/cli

Hi all, this is my first post. I have a native function inside a managed (c++/cli) mixed-mode library that calls a seperate native dll. Here is the native function that initializes some function pointers using windows GetProcAdress: //in header static HMODULE hDll; static void (*MYDLL_Func1)(void*); static void (*MYDLL_Func2)(void); ...

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 using swapcontext(context_1,context_2...