Accessing the parents arguments from a child function call

monkyyy crazymonkyyy at gmail.com
Sat Jul 5 03:02:44 UTC 2025


```d
auto bar(int i){
   foo()
}
unittest{
   bar(3);
}
```
Given any definition of foo, any compiler bugs, how would you 
detect the `3` from `foo`?

___

My attempts at scanning the call stack didn't work but for anyone 
attempting it, I believe this breakdown of control flow may be 
part of the solution

```d
import std;
void bar(ubyte i){
     (&i).writeln("arg");
     //float f;
     //bool b;
     foo();
}
//---

//class badgoto:Throwable{
//    this(string){}
//    this(){}
//}
enum ubyte senty=117;
void foo(){
     int[0] callstack;
     static int call;
     static void* start;
     static void* start2;
     static void* end;
     static ubyte copy;
     switch(call++){
         case 0:
             start=cast(void*)&callstack;
             start2=cast(void*)&callstack;
             try{bar(senty);}//1st
             //catch(badgoto){}//3rd
             catch(Error){}
             copy=*cast(ubyte*)start2;
             break;
         case 1://2nd
             end=cast(void*)&callstack;
             start.writeln("start");
             end.writeln("end");
             while(start>end && *(cast(ubyte*)start)!=senty){
                 writeln(start,":",*(cast(ubyte*)start));
                 start--;
             }
             writeln(start,":",*(cast(ubyte*)start),"last");
             "---".writeln;
             start.writeln;
             end.writeln;
             start2=start2+(end-start);
             start2.writeln;
             throw new Error("");
             break;
         default:
             copy.writeln;
     }
}
unittest{
     bar(3);
     foo;
}
```


More information about the Digitalmars-d-learn mailing list