Well, this can only be done by leaking a pointer to a writable typed constant. Here is an example, which is a rather confusing way to print the beast number:
program NaughtyNaughtyVeryNaughty;{$J+} {$APPTYPE CONSOLE} procedure Test(out MyPrivatesExposed: PInteger); const I: Integer=665; begin MyPrivatesExposed := @I; inc(I); end; var I: PInteger; begin Test(I); Writeln(I^); Readln; end.
Since the locality region is limited by the function in which it is defined, the approach described above is the only possible solution.
David heffernan
source share