There is a very dangerous element to creating functions on the heap. Let's say some moron programmer deletes said function using delete and then calls it later. Very bad medicine my friends.
But Fordy is right in that you could approach it that way but I would definitely limit access to that function via a class so that it could not be deleted accidentally or otherwise. And Fordy was not recommending that you do it that way if I know Fordy as well as I think I do. He is merely showing another way to do it, which is what he specializes in.
i dont need a new block of code, i need the same block of code accessable from 2 seperate addresses that i could call using pointers. i need a unique address for each function, even if they are identical in what they do.
If they are the same function (or block of code) why the heck do you need two unique addresses for each function???
Perhaps and illustration in assembly would suffice.
Code:
__LI proc
ARGS v1:DWORD,v2:DWORD,f1:QWORD
push bp
mov bp,sp
fild [v2]
fisub [v1]
fmul [f1]
fiadd [v1]
pop bp
ret
__LI endp
extern "C" double LI(unsigned long v1,unsigned long v2,double f1)
Now LI will be linked in (assuming you have included the source file or the binary file in the link) and the compiler will give it an address.
If you need to access this function from your program, you simply call it like this:
LI(v1,v2,f1);
or in assembly
call __LI
or
call <some address>
Thankfully we can use function names so we don't have ugly looking call instructions sitting around. Since there are no classes and no protection mechanisms in this code - LI can be called from anywhere inside of your program. So if it is the same block of code - it does not need 2 distinct addresses because that would simply be a copy of the original function and would waste space.
In C this would be flagged as an error and would not compile since the function prototypes would be exactly the same. The compiler will not create two copies of the same function and place them at distinct addresses and you should not either.