Clarifying 'const' terminology

Derek Parnell derek at psych.ward
Sat Jul 8 16:44:10 PDT 2006


On Sun, 09 Jul 2006 08:03:52 +1000, Sean Kelly <sean at f4.ca> wrote:



> In the realm of compiler optimization techniques, there's another issue  
> as well: can the compiler assume that, because it is evaluating a const  
> reference, that the underlying data will not change while that reference  
> is in use.

Just to clarify, are you saying that while a function that was passed a  
'const' reference is running, can the compiler assume that so other  
concurrently running function will change the passed data?

> This is the truly sticky part, and is I think a large reason why Walter  
> hasn't settled on anything yet.  For example, consider "const by  
> default":
>
>      void readWrite( inout T val ) {}
>      void readOnly( in T val ) {}
>
>      T val;
>
>      readWrite( inout val );
>      ...
>      readOnly( val );
>
> In the above, because a mutable reference to val is obtained before  
> readOnly is called, can the compiler assume that the contents of val  
> will not change while readOnly is being evaluated?  Can it ever make  
> that assumption for the entire life of the program after readWrite is  
> called?

If functions are not being run concurrently, I think it can. Because while  
the code in readOnly() is executing, how can code in other functions  
execute if they are not called somehow by readOnly itself? Or am I missing  
something (again <g>).

-- 
Derek Parnell
Melbourne, Australia



More information about the Digitalmars-d-learn mailing list