suggestion: read-only array-reference
Johan Granberg
lijat.meREM at OVEgmail.com
Thu Jul 20 04:09:47 PDT 2006
Hasan Aljudy wrote:
> Additionally, we can use the same rational for builtins that Walter used
> for other things: having this built-in means that the compiler knows
> about the read-only array idiom, and can provide meaningful error
> messeges and prevent any possible attempt to break the contract (using
> asm or whatever pointer tricks available).
While I'm all for a built in const I disagree with the last paragraph. I
don't want the compiler to try to prevent me subverting the protection
by using casts or pointer tricks (c++ had const cast for a reason). I
have used some c++ libraries where some values where const when not
strictly needed, and I was able to achieve the desired behavior by the
use of a cast. (This is of course unsafe and should never bee used in
library code, just in quick and dirty applications or internally in your
own code base where you can use this as a shortcut)
More information about the Digitalmars-d
mailing list