Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I call function pointers directly?

Tags:

People also ask

How do you call a function with a pointer?

Calling a function using a pointer is similar to calling a function in the usual way using the name of the function. int length = 5; // Different ways to call the function // 1. using function name int area = areaSquare(length); // 2. using function pointer (a) int area = (*pointer)(length); // 3.

Can we use pointers with functions?

You can use pointers to call functions and to pass functions as arguments to other functions. You cannot perform pointer arithmetic on pointers to functions.

What Cannot be done with function pointers?

What will we not do with function pointers? Explanation: As it is used to execute a block of code, So we will not allocate or deallocate memory.

Can you pass pointers to functions?

Pass-by-pointer means to pass a pointer argument in the calling function to the corresponding formal parameter of the called function. The called function can modify the value of the variable to which the pointer argument points. When you use pass-by-pointer, a copy of the pointer is passed to the function.


The question I'm asking won't be used in production, it's pure curiosity


Let's say I have a function, and its prototype is:

int myFunc(int, char*);

Supposing I know the static memory address (which is, for example, 0xC0DE), I can do this:

int (__cdecl* myFuncPtr)(int, char*) = (int(__cdecl*)(int, char*)) 0xC0DE;
myFuncPtr(1, "something");

Now, can I somehow call that function in one line, without the defining it? Like this:

((int(__cdecl*)) 0xC0DE)(1, "something");