Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You're trying to rely on undefined behaviour: Once the inner function goes out of scope because the outer one does exit, the behaviour of calling that inner function through some pointer is undefined. Anything might happen. The fact that things accidentially worked for the integer case does not imply that you can expect the same for double, or that you can even expect the same for int over different compilers, different compiler versions, different compiler flags or different target architectures.</p> <p>So don't rely on undefined behaviour. Don't claim to have “heed[ed] the warnings” when in fact you acted against those warnings. The warning clearly states:</p> <blockquote> <p>If you try to call the nested function through its address after the containing function has exited, all hell will break loose.</p> </blockquote> <p>There are no <a href="http://en.wikipedia.org/wiki/Closure_%28computer_science%29" rel="nofollow">closures</a> in C, so there can't be currying in this sense. You can get similar effects if you pass along some data to function invocations, but that will not look exactly like a normal function call, so it won't feel like normal currying. C++ has more flexibility there, as it allows objects to behave syntactically like functions. In the C++ world, currying is usually called “<a href="http://www.boost.org/doc/libs/1_51_0/libs/bind/bind.html" rel="nofollow">binding</a>” of function parameters.</p> <p>If you really want to know why one piece of code worked but the other failed, you can take the assembly code (generated e.g. by <code>gcc -S -fverbose-asm</code>) and simulate the execution in your head, to see what happens to your data and stuff. Or you may use the debugger to see where things fail, or data locations change. Might take some work, and I doubt it's worth the time.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload