Reputation: 37
I am porting assembly code to C++ and I have some problems porting a portion of it.
I have a pointer declared as:
void* function;
and it is pointing to a function call:
void* function = getfunction(lib, fname);
I have a inline assembly code which I have to migrate to C++:
__asm { call function }
How to call this pointer in C++?
Please note that the arguments lib
and fname
are of type void*
.
And void* function
points to value returned by getfunction()
.
Upvotes: 1
Views: 200
Reputation: 14093
Look at the following example :
// ptrFunc is the name of the pointer to the getFunction
void* (*ptrFunc)(void*, void*) = &getfunction;
// ... Declaring whatever lib and fname are
// Now call the actual function by using a pointer to it
ptrFunc(lib, fname);
// Another form of how to call getFunc might be :
(*ptrFunc)(lib, fname);
Also, you can pass function pointers to another function such as :
void *getFunction(void* lib, void* fname)
{
// Whatever
}
void myFunction( void* (*ptrFunc)(void*, void*) )
{
// void *lib = something;
// void *fname = something else;
ptrFunc(lib, fname);
}
int main()
{
void* (*ptrFunc)(void*, void*) = &getfunction;
// Passing the actual function pointer to another function
myFunction(ptrfunc);
}
Upvotes: 0
Reputation: 612794
In what follows, I am assuming that the entire function call is encapsulated by
__asm { call function }
In which case this is a function pointer that can be declared like this:
void (*function)(void);
The __asm
block does not push parameters onto the stack. Therefore the parameter list is empty. And the __asm
block does not extract a return value. So the function has void
return type.
You assign to the function pointer in just the same way:
function = getfunction(lib, fname);
And you call it like this:
function();
Upvotes: 1