[fpc-pascal] Pointer to temporary string

Jonas Maebe jonas.maebe at elis.ugent.be
Sun Mar 11 15:56:56 CET 2012


On 11 Mar 2012, at 15:46, cobines wrote:

> Is storing and using pointers to temporary strings safe?

No.

> Like in the
> following program. I think I remember reading on the mailing list that
> it is not, but I cannot find it. How can I prove one way or the other?

The only thing you can prove is finding code that crashes. You can't prove that it's safe, because it's impossible to prove a negative (namely that no code sequence exists that will crash).

> I could not get the program to crash, even if I used 20 variables, it
> didn't show any wrong result. Valgrind and Dr. Memory didn't show any
> problems.

Nevertheless it's not safe. It depends on management of temporary variables of the compiler, which in itself depends on the performed optimizations and compiler version. Just don't do it.


Jonas


More information about the fpc-pascal mailing list