Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function pointers?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Experts:

I have an assignment coming up that requires me to write an RPC (Remote Procedural Call) that will interface with my main program. The RPC needs to be written to pass into a function pointer parameter.

What I want to ask is, how does function pointers make the code any more modular/independent than it already is? Let say... using an ordinary function? I do not understand the modularity between using a function pointer and an ordinary function. Can someone please clear this up for me?

Thanks.
Sedge Troll
 
In this case the purpose of the function pointer is so the class will know what to call. You can have a class called

AMathematicalOperation

it can have a function called compute.
it can also have a private member that is a funciton pointer which you pass in.

Functions you could pass in would be
Add,subtract,multiply, etc...

This is a very simple example... but the funciton pointer provides a diversity for how the program will behave

Matt
 
...in reality - every function that you are calling has the offset in memory and the name of the function is simply the alias for this offset. But if you have this function as class member or via includes - you obtain this pointer imlicitly because you have the alias under your hand, it is like the alias for the declarated variable that is also some memory offset that you are accessing...

but when you want to call exported functions from another libraries without linking with it - you have not alias for the function because the code of this dll can be not available for you but if this dll has known exported funcitons - you can obtable the pointers on them by GetProcAddress - more about this you can read in the MSDN section about this function...

Have a good luck Issahar Gourfinkel
senior software engineer
Softwatch LTD
Israel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top