[fpc-devel] Const optimization is a serious bug

michael.vancanneyt at wisa.be michael.vancanneyt at wisa.be
Thu Jul 7 14:13:59 CEST 2011



On Thu, 7 Jul 2011, Alexander Klenin wrote:

> On Thu, Jul 7, 2011 at 22:10,  <michael.vancanneyt at wisa.be> wrote:
>> Sigh....
>>
>> That's what I've been saying all along. You don't even need strings for it.
>> Plain records and integers will do it just as well.
>
> Well, I am sorry, but do you all (not only Michael, I'm just
> responding to the last mail in the thread)
> really think I am stupid enough to not know it?
> It is quite understandable that FPC developers want to defend the status quo,
> but can you please do it by responding to the argument OP and I actually make?

The problem is your understanding of const.

The declaration

Procedure DoSomething(const A : Type);

means:

   YOU promise not to change A inside DoSomething.

Based on this promise, the compiler may decide to do some optimization.
It will also warn you if it detects inside the code that you break your promise.

The declaration

Procedure DoSomething(const A : Type);

does NOT mean:

   The compiler promises that A does not change inside DoSomething.

You seem to think that this should be the case. Well, it is not the case.

Const is an aid from you to the compiler. Not an aid from the compiler to you.

As soon as you understand this subtle difference, the problem disappears.

Michael.




More information about the fpc-devel mailing list