stack-frame

How does D allow delegates as template parameters?

。_饼干妹妹 提交于 2020-01-03 17:17:13
问题 In "The D Programming Language" by Andrei Alexandrescu, there's an example where a delegate is taken as a template parameter: T[] find(alias pred, T)(T[] input) if(is(typeof(pred(input[0])) == bool)) { for(; input.length > 0; input = input[1 .. $]) { if (pred(input[0])) break; } return input; } unittest { int[] a = [1,2,3,4,-5,3,-4]; int z = -2; auto b = find!(delegate(x) { return x < z; })(a); asssert(b == a[4..$]); } Alexandrescu explains that this works because a delegate is actually a fat

How do I get the executing object for a stackframe?

淺唱寂寞╮ 提交于 2019-12-30 04:18:25
问题 When using reflection it is possible to obtain the call stack (apart from that it can be a crude approximation due to JIT optimizations) using System.Diagnostics.StackTrace and examine the StackFrame objects contained. How can I get a reference to the object (the this-pointer) on which a method in a stack frame is executing? I know I can get the MethodBase by calling GetMethod() on the stack frame object, but what I'm looking for is something along the lines of GetObject() (which'd naturally

How do called functions return to their caller, after being called?

浪尽此生 提交于 2019-12-22 03:44:30
问题 I read that when a function call is made by a program, the called function must know how to return to its caller. My question is: How does the called function know how to return to its caller? Is there a mechanism working behind the scenes through the compiler? 回答1: The compiler obeys a particular "calling convention", defined as part of the ABI you're targeting. That calling convention will include a way for the system to know what address to return to. The calling convention usually takes

Delphi 64 bit debugging using runtime libs has wrong stack frame active

柔情痞子 提交于 2019-12-12 10:44:30
问题 I ran into a Win64 debugging problem where it looks like we are "missing" debug info. So I did some research and re-created all my .dproj files for our flagship product. This helped, as I got my "missing" blue balls back. But now I run into a new problem: the (top) stack frame displayed in the stack display window appears to be wrong, which results in local variables not being displayed in the local variables pane, and also not when hovering the mouse above some variable. But when I select

How to write a function which return a pointer to the stack

拜拜、爱过 提交于 2019-12-11 13:04:07
问题 After reading the following question, I understand that there no such thing exist (at least not 'portable'). However I am starring at the following piece of code from mono code base, which return a pointer to the stack: static void * return_stack_ptr () { gpointer i; return &i; } I am surprised that the above code can even work on arch such as PowerPC, I would have assumed this would only work on x86 (and maybe only gcc). Is this going to work on PowerPC ? 回答1: The purpose of the stack is