New linked list

Sean Kelly sean at f4.ca
Tue May 16 13:05:46 PDT 2006


Walter Bright wrote:
> 
> I have been thinking along the lines of making 'const' a promise *by the 
> programmer* not to modify the data, and then the compiler will *assume* 
> the promise is kept.

How would the programmer know whether data was being modified?  For example:

     class MyClass {
         char[] name() {
             if( !m_name )
                 m_name = readNameFromDB();
             return m_name;
         }
     }

     const MyClass ref = new MyClass;
     printf( "%.*s\n", ref.name );

It seems this could impose maintenance problems and may require code the 
user wants to const-qualify to be inspectable.  Or are you suggesting 
there would be some language support for checking this?  And if so, how 
would you avoid a Cpp-like syntax?

 > Your idea is a way to enforce the issue. The
> problem is that changing page protection attributes is very slow - but 
> one could afford the cost in "debug compiles."
 >
> This would be a cool way to implement "const-correctness" without the 
> hassle and cruft. There are still problems, though. You can't make part 
> of an object readonly with hardware.

Yeah it's kind of a sledgehammer for delicate work.  But it might prove 
useful for tracking down some const violations.  I may experiment with 
it from a library perspective and see if I can find a usable syntax.


Sean



More information about the Digitalmars-d-announce mailing list