Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4106
Number of posts: 14016

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Re: Const parameter Posted by Actor21 on 26 Sept 2012 at 3:09 PM

: 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. 


Thread Tree
TheEvan Const parameter on 22 Sept 2012 at 6:04 AM
quikcarlx Re: Const parameter on 22 Sept 2012 at 6:56 PM
TheEvan Re: Const parameter on 23 Sept 2012 at 6:15 AM
quikcarlx Re: Const parameter on 23 Sept 2012 at 6:01 PM
TheEvan Re: Const parameter on 24 Sept 2012 at 2:41 AM
Actor21 Re: Const parameter on 24 Sept 2012 at 2:37 PM
TheEvan Re: Const parameter on 25 Sept 2012 at 2:40 AM
Actor21 Re: Const parameter on 26 Sept 2012 at 3:09 PM
TheEvan Re: Const parameter on 23 Sept 2012 at 6:17 AM
TheEvan Re: Const parameter on 23 Sept 2012 at 6:19 AM



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.