function-pointers

Passing a pointer to a function that doesn't match the requirements of the formal parameter

int valid (int x, int y) { return x + y; } int invalid (int x) { return x; } int func (int *f (int, int), int x, int y) { //f is a pointer to a function taking 2 ints and returning an int return f(x, y); } int main () { int val = func(valid, 1, 2), inval = func(invalid, 1, 2); // <- 'invalid' does not matc...

GDB not hitting breakpoints, probably because of function pointers. How to set breakpoints in this case?

Hello, I am trying to hit a breakpoint that appears early in the code, but gdb (ddd) misses it each time. At first I thought it was because of templates, but gdb seems to cope with that. I'm guessing the problem is that the choice of which function to execute (here, doit), is only known at execution time ("function pointers"), but judge ...

How does dereferencing of a function pointer happen?

Why and how does dereferencing a function pointer just "do nothing"? This is what I am talking about: #include<stdio.h> void hello() { printf("hello"); } int main(void) { (*****hello)(); } From a comment over here: function pointers dereference just fine, but the resulting function designator will be immediately c...

Function pointers in Objective-C

I have the following scenario: Class_A - method_U - method_V - method_X - method_Y Class_B - method_M - method_N HttpClass - startRequest - didReceiveResponse // is a callback Now I want to realize these three flows (actually there are many more, but these are enough to demonstrate my question): Class_A :: method_X ...

Embedding Python and adding C functions to the interpreter

I'm currently writing an applications that embedds the python interpreter. The idea is to have the program call user specified scripts on certain events in the program. I managed this part but now I want the scripts to be able to call functions in my program. Here's my code so far: #include "python.h" static PyObject* myTest(PyObject...

Synchronizing indices of function pointer table to table contents

In the embedded system I'm working on, we are using a table of function pointers to support proprietary Dynamic Libraries. We have a header file that uses named constants (#define) for the function pointer indices. These values are used in calculating the location in the table of the function's address. Example: *(export_table.c)...

Member Function Pointer not quite right

I have a SpecialisedRedBlackTree class that is templated. My Month class is not. In my Month class I have a private member which is an instance of SpecialisedRedBlackTree: SpecialisedRedBlackTree<Day> m_windSpeedTree; As you can see it will take the Day class/object (please correct me on any terms I get wrong). In my Month class, I...

Does this have anything to do with endian-ness?

For this code: #include<stdio.h> void hello() { printf("hello\n"); } void bye() { printf("bye\n"); } int main() { printf("%p\n", hello); printf("%p\n", bye); return 0; } output on my machine: 0x80483f4 0x8048408 [second address is bigger in value] on Codepad 0x8048541 0x8048511 [second address is smaller in v...

In C: sending func pointers, calling the func with it, playing with EIP, jmp_buf and longjmp

I need to make sure i understand some basic stuff first: how do i pass function A as a parameter to function B? how do i call function A from inside B ? Now for the big whammy: I'm trying to do something along the lines of this: jmp_buf buf; buf.__jmpbuf[JB_PC] = functionA; longjmp(buf,10); Meaning that I want to use longjmp in o...

Create a function pointer which takes a function pointer as an argument.

I'm trying to create a function pointer that takes a function pointer as an argument, but am not sure how to go about it... I was advised to try typedef-ing one of my function pointers, but get the same error. Could someone help me with the correct syntax? int 186 main(int argc, char **argv) 187 { 188 int i; 194 typ...

c++ generic pointer to (member?) function

I can't seem to declare a generic pointer to function. Having these 2 functions to be called: void myfunc1(std::string str) { std::cout << str << std::endl; } struct X { void f(std::string str){ std::cout<< str << std::endl;} }; and these two function callers: typedef void (*userhandler_t) (std::string); struct example {...

Create thread is not accepting the member functon

I am trying to create a class for network programming. This will create a general purpose socket with thread. But when I tried to creat the thread using createthread(). The third argument is producing errors. And from the net I came to know that I can't use the member functions as a argument to the createthread(). Is there any thing by...

Functions as pointers in Objective-C

This is a question from Learn Objective-C on the Mac... Functions as pointers What I typed in, as per the recipe, was: NSString *boolString (BOOL yesNo) { if (yesNo) { return (@"YES"); } else { return (@"NO"); } } // boolString The pointer asterisk in the first line doesn't seem necessary, yet deleting it results in an error message...

Separating functions to a separate header that rely on another function not inside the header?

I have several C scripts that will all have the same format(functions), but occasionally the actual code within a few functions. I am trying to separate a function into an external header file, but the issue is this: int FunctionImExtracting() { //some code FunctionThatCannotBeExtractedButTheFunctionSignatureWillAlwaysRemainThe...

And now for a complete change of direction from C++ function pointers

I am building a part of a simulator. We are building off of a legacy simulator, but going in different direction, incorporating live bits along side of the simulated bits. The piece I am working on has to, effectively route commands from the central controller to the various bits. In the legacy code, there is a const array populated w...

c++/cli pass (managed) delegate to unmanaged code

How do I pass a function pointer from managed C++ (C++/CLI) to an unmanaged method? I read a few articles, like this one from MSDN, but it describes two different assemblies, while I want only one. Here is my code: 1) Header (MyInterop.ManagedCppLib.h): #pragma once using namespace System; namespace MyInterop { namespace ManagedCppL...

Passing a template func. as a func. ptr to an overloaded func. - is there a way to compile this code?

Just a general c++ curiosity: This code below shouldn't compile because it's impossible to know which to instantiate: temp(const int&) or temp(const string&) when calling func(temp) - this part i know. What i would like to know is if there is anything i can do to the line marked PASSINGLINE to get the compiler to deduce that i want ...

function objects versus function pointers

Hi All, I have two questions related to function objects and function pointers, Question : 1 When I read the different uses sort algorithm of STL, I see that the third parameter can be a function objects, below is an example class State { public: //... int population() const; float aveTempF() const; //....

Function lfit in numerical recipes, providing a test function

Hi I am trying to fit collected data to a polynomial equation and I found the lfit function from Numerical Recipes. I only have access to the second edition, so am using that. I have read about the lfit function and its parameters, one of which is a function pointer, given in the documentation as void (*funcs)(float, float [], int)...

Function pointers usage

Possible Duplicate: How does dereferencing of a function pointer happen? Hi All, Why these two codes give the same output, Case 1: #include <stdio.h> typedef void (*mycall) (int a ,int b); void addme(int a,int b); void mulme(int a,int b); void subme(int a,int b); main() { mycall x[10]; x[0] = &addme; x[1] = &sub...