What's wrong with just a runtime-checked const?

Reiner Pope reiner.pope at gmail.com
Tue Jul 18 01:11:06 PDT 2006


xs0 wrote:

> Well, I don't think you completely missed the point, but doing it would 
> cause all sorts of issues:
> - where should the tag be placed? you can't put it inside the pointer, 
> as there are no free bits; you also can't put it next to a pointer, as 
> it would affect memory layout of structures (in particular, it would 
> make debug-built and release-built code non-interoperable).
This is (to me) the biggest issue to be resolved. I think that the best 
implementation would involve modifying the signature of functions to 
accept extra variables, signalling isConst. I know, this damages 
release/debug interoperability, so can you tell me which functions that 
would cause problems for? All that I can think of is (a) exported 
functions in libraries, and (b) functions that inline assembler calls. 
Am I missing any?


> - it can still be trivially subverted - just cast to int/long and back
> - you can't just check at the beginning of a function - you can get the 
> pointer in the middle of it; you can also get the pointer in _another_ 
> function (from a global or in a multi-threaded program); checking at 
> every access would be too expensive, I think, even for a debug build
> 
> 
> xs0



More information about the Digitalmars-d-learn mailing list