: How do i check the size in which it executes?
: The compiler is quite established, so could it be that it still
: utilize referencing when Const is added, but just do not attempt to
: warn user when the Const parameter is reassigned?
:
I've looked at the link you posted and it appears that my guess as to how your compiler works is incorrect. It says
"no assumptions should be made about how const parameters are passed to the underlying routine. In particular, the assumption that parameters with large size are passed by reference is not correct."
and
"specifying const is a contract between the programmer and the compiler. It is the programmer who tells the compiler that the contents of the const parameter will not be changed when the routine is executed, it is not the compiler who tells the programmer that the parameter will not be changed."
This latter statement is the converse of how Turbo Pascal works and I think it is also contrary to the standard. Apparently using
const parameters amounts to promising the compiler that you will not chance the value, allowing the compiler to make certain optimizations. My guess is that if you do not keep that promise you may be creating a bug.
If
const parameters behave this way in Free Pascal then I think they are to be avoided. My expectation when using
const parameters is that they are passed by reference and the compiler will not let you make assignments to them. If you really do not have enough memory to pass the parameter by value then better to use a
var parameter and include a comment in the code that the value should not be changed.
For what it's worth I think the program in your link is simply bad code.
Var
S : String = ’Something’;
Procedure DoIt(Const T : String);
begin
S:=’Something else’;
Writeln(T);
end;
begin
DoIt(S);
end.