<div dir="ltr"><div>Hi all,</div><div>In both examples below I'm attempting to call a function from the function's address. The first example works but the second doesn't. I suspect I'm missing something fundamental about function invocations. Can someone explain why the second example fails? First:</div><div>
<p class="gmail-p1">func doNothing() {}<br>
func call(_ ptr: UnsafePointer<() -> ()>) { <br>
<span class="gmail-s1"> </span>ptr.pointee() <br>
} <br>
var x = doNothing<br>
call(&x) </p><p class="gmail-p1"></p><br>There's no crash there. Everything works as expected - in that it does nothing. So far so good, but this crashes:</div><div><br></div><div>
<p class="gmail-p1">doNothing<br><font color="#999999">
$R16: () -> () = 0x0000000100561060 $__lldb_expr2`__lldb_expr_1.doNothing () -> () at repl.swift:1</font><br>
let ptr = UnsafePointer<() -> ()>(bitPattern: 0x0000000100561060)<br>
ptr!.pointee() <br>
</p><br>Crashes! Also, I notice that the address of the pointee changes each time I ask for it:</div><div><br><p class="gmail-p1">
ptr!.pointee <br><font color="#999999">
$R17: () -> () = 0x0000000100567<span style="background-color:rgb(0,255,0)">440</span> $__lldb_expr50`partial apply forwarder for reabstraction thunk helper from @callee_owned (@in ()) -> (@out ()) to @callee_owned () -> () at repl49.swift<br></font>
ptr!.pointee <br><font color="#999999">
$R18: () -> () = 0x0000000100567<span style="background-color:rgb(0,255,0)">740</span> $__lldb_expr52`partial apply forwarder for reabstraction thunk helper from @callee_owned (@in ()) -> (@out ()) to @callee_owned () -> () at repl51.swift</font><br></p>Questions:<br>1. Why does the first example succeed but the second one fail?<br>2. Why does the pointee address change on sequential calls?<br>3. What is a reabstraction thunk helper (do I want to know :))<br><br>I know it's a lot to ask, if there's something you would rather point me to to read that's a-ok!<br><br>Thanks,<br>Lou<br></div></div>