Could const/invariant be optional?

Craig Black cblack at ara.com
Mon Mar 31 11:33:25 PDT 2008


"Steven Schveighoffer" <schveiguy at yahoo.com> wrote in message 
news:fsqvqc$1cr4$1 at digitalmars.com...
> "Craig Black" wrote
>>I think most would agree that const is more useful for some programs, but 
>>more of an annoyance for others.  Could the const be disabled by a 
>>compiler option?  If I disabled const when compiling a source file, I 
>>could still rely on libraries that supported const, but I could write code 
>>as if there were no const constraints.
>
> The problem would be in code that depends on const being enforced, such as 
> for multi-threaded programs.  It would be impossible to determine where 
> those would be without more annotation, and even then, you are relying on 
> authors of the code to properly annotate something that is not necessary 
> in the normal context.  Think of how eager most coders are to document 
> their code rather than get it working :)
>

It would be easy enough to insert some sort of flag that would denote 
whether a particular module is const correct or not, and have the 
compiler/linker make some sort of guarantee for safety purposes.

Anyway, I don't really care enough about the idea to debate about the 
details.  It was just an idea.

-Craig 





More information about the Digitalmars-d mailing list