function-pointers

C++0x template function object inference

I'm a Scala/Java programmer looking to reintroduce myself to C++ and learn some of the exciting features in C++0x. I wanted to start by designing my own slightly functional collections library, based on Scala's collections, so that I could get a solid understanding of templates. The problem I'm running into is that the compiler doesn't s...

Function pointers in C

The following code (a function prototype): void parse_ini(FSFILE *fp, void(*secFunc)(char*), void(*varFunc)(char*, char*)); presents errors when compiled: util\setup.c:38: error: syntax error before '*' token util\setup.c:38: error: 'parse_ini' declared as function returning a function util\setup.c:38: error: syntax error before 'voi...

Accessing a Pointer to a pointer in C++

Hi I am using a 3rd party library in my iPhone application that uses C++ one of the methods i need to use returns a pointer to a pointer of a class. like follows. DLL classAttributes** getAttributes(); I can successfully call the method and return the value into a pointer to a pointer like so; classAttributes **attributes = cPPClass-...

Using function pointers?

I'm not yet very familiar with these but maybe someone can shine light on this example. Imagine I have class CFoo and it will have a function to add a handler and a function which is a function pointer. So something like this: class CFoo { int *pointedFunc(int a, int b) = 0; void setFunc(int *func(int a, int b)) { pointedFunc = ...

How to properly define a function pointer in struct, which takes struct as a pointer?

I have a struct with a callback function, the callback function needs a pointer to the structure in order to do its operation. How do I properly define these elements such that is will compile without warnings? typedef struct { // some fields required for processing... int (*doAction)(struct pr_PendingResponseItem *pr); } pr_P...

Store a "pointer to function" in fortran 90 ?

in fortran, you can pass a function/subroutine A as an argument to another function/subroutine B, but can you store A for later retrieval and use? for example, this is allowed in C int foo(float, char, char) { /*whatever*/}; int (*pointerToFunction)(float, char, char); pointerToFunction = foo; In Fortran you can pass a subroutine as...

What algorithm does gcc use to convert calls through function pointers to direct calls?

I've heard that recent versions of gcc are very good at converting calls through function pointers to direct calls. However, I can't find anything about it on the web or the quick look through gcc's source code. Does anyone know if this is actually true and if so, what algorithm does it use to do this? ...

get 'ldftn' function pointer in C#

in cil code, ldftn is used to get the function pointer address to call the delegate constructor(i.e. .ctor(object, native int)). How to get the function pointer used to construct delegate in C#? ...

Base class's function pointer points to child class's member function?

I know it sounds awefully confusing, I have a base template class which has a function pointer, a child class(which is no longer a template class) needs to use that function pointer to point to a child class's member function, and I get all kinds of errors.. Did I violate some universal law of C++? here is the pseudo code: template <cla...

What does the pointer value of a function pointer represent?

Trying to understand what the pointer to function actually represent? Is it the address in the code segment where the function resides? For ex: this piece of code: #include <stdio.h> void foo(void) { } int main(void) { int a = 10; printf("a's address: %p\n", &a); printf("foo's address: %p\n", foo); return 0; } ... p...

What is guaranteed about the size of a function pointer?

In C, I need to know the size of a struct, which has function pointers in it. Can I be guaranteed that on all platforms and architectures: the size of a void* is the same size as a function pointer? the size of the function pointer does not differ due to its return type? the size of the function pointer does not differ due to its param...

Unable to resolve overloaded class methods in template delegate.

Background: I'm using a delegation technique to abstract access to arbitrary object methods, but I'm having some issues where the linker is concerned. Consider the following class, ContextNode. template <class ObjectType, class GetType, class SetType> class ContextNode: public ContextNodeBase { public: ContextNode(ObjectType* tar...

How to assign address of function pointer according to char*?

Hello everyone! I am writing a C program that could be simplified if I manage to do something like this: int (*func)(int); char* str= "adder"; func = str; func(2); I create a function pointer, a char*, and I try to assign the name of the function to the pointer through that char*. In this example, the adder(int) function exists. Is ...

C++ method-invoking template-function not able to call overloaded methods.

If you have this generic function: template<class type, class ret, class atype1, class atype2, class atype3> ret call3(type *pClass, ret(type::* funcptr)(atype1, atype2, atype3), atype1 arg, atype2 arg2, atype3 arg3) { //do some stuff here return (pClass->*funcptr)(arg, arg2, arg3); } and you do this: class MyClass { public...

Use C structs only and stay OOPy?

Say you have: struct c_struct { int value; /* other stuff */ void (* dump)(); }; and you'd like to, at some point: c_struct_obj->dump(); I assume there's no way you could instantiate a c_struct object such that its particular "dump" function knows its particular "value" the way C++ methods know member variables (via the im...

How do you store a function pointer in an ObjectiveC class?

Some of Apple's obj-c API's still use C functions, e.g.: -(NSArray * ) sortedArrayUsingFunction: (NSInteger (*)(id, id, void *))comparator context:(void *)context ...which is great, except I'm struggling to see how you can store fn-pointers inside ObjC classes. e.g. to share the same "sort" function in different parts of your pr...

Using a pointer to a function as a template parameter

(C++) I've got a number of Entry classes, and got BaseProcessor interface which incapsulates Entry processing logic. (see code below) The Entry doesn't provide operator<(). The BaseProcessor provides a pointer to less(Entry, Entry) function which is specific for particular BaseProcessor implementation. I can use the function pointer to...

How do return an enum in a typedef of function pointer?

#include <stdio.h> enum bool { true, false }; typedef bool (*compare_fun) (int, int); I get an error when I enter the above code. How do I make a function pointer that needs to return a boolean? ...

C++ for_each() and the function pointer

I am try to make the myFunction give me a sum of the values in the array, but I know I can not use a return value, and when I run my program with the code as so all I get is a print out of the values and no sum why is that? void myFunction (int i) { int total = 0; total += i; cout << total; } int main() { int array[] = { 1, 2, 3, 4, 5...

Implementing a generical 'map' function over arrays in C

Hi! I'm having difficulties implementing a generic 'map' function over arrays. I started with the following draft: void MapArray(void * src, void * dest, void * (f)(void *), size_t n, size_t elem) { unsigned int i = 0, j = 0; void * temp = malloc(elem); for(i = 0; i<n, i++) { temp = (f)((char *) src) + i)); for...