[fpc-devel] Const optimization is a serious bug
Hans-Peter Diettrich
DrDiettrich1 at aol.com
Tue Jul 5 19:20:56 CEST 2011
cobines schrieb:
> procedure mclass.dot(const s: string);
>
> Here you know that you cannot modify 's'. But you may not know that
> you cannot also change mclass.ftext variable, which actually 's'
> points to because apparently someone called
> mclass.dot(mclass.fsometext).
You *can* change mclass.ftext, but this can cause *trouble*.
> Maybe it is programmer error and it should be said: "never call
> mclass.dot with mclass.ftext as a parameter because it may crash".
> Maybe the const should have never been there in the first place. I
> would say if procedure writes to some non-local strings, never add
> 'const' to parameter.
Good advice :-)
DoDi
More information about the fpc-devel
mailing list