Could const/invariant be optional?

Steven Schveighoffer schveiguy at yahoo.com
Mon Mar 31 08:26:04 PDT 2008


"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 :)

-Steve 





More information about the Digitalmars-d mailing list