stack frame & dangling pointer weirdness

ag0aep6g anonymous at example.com
Thu Apr 21 06:06:57 UTC 2022


On 21.04.22 07:49, Alain De Vos wrote:
> int *p=null;
> void myfun(){
>      int x=2;
>      p=&x;
>      writeln(p);
>      writeln(x);
> }
> myfun();
> *p=16;
> writeln(p);
> writeln(*p);

`p` is no longer valid after `myfun` returns. Dereferencing it is an error.

The two `writeln` calls in `main` re-use the memory that `p` points to 
for their own purposes.


More information about the Digitalmars-d-learn mailing list