Modify Function Pointer to Take Additional Parameters

Chris Wright via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Feb 19 14:34:48 PST 2016


On Fri, 19 Feb 2016 21:57:46 +0000, Yuxuan Shui wrote:

> I don't think it's safe to convert between function pointer with
> different number of arguments... It's possible to mess up the stack
> frame.

I tested this a fair bit today, and I haven't been able to do any of the 
nefarious things I expected to be able to do. No overwriting variables in 
the caller's scope, no smashing stack pointers, etc.

I was surprised by this result, but in retrospect, it's relatively 
obvious. The caller pushes variables onto the stack and sets the stack 
pointer for the callee. It wouldn't send a stack pointer that pointed 
into its own stack frame.


More information about the Digitalmars-d-learn mailing list