any news on const/invariant?
0ffh
frank at frankhirsch.youknow.what.todo.net
Mon Nov 26 17:47:31 PST 2007
Bill Baxter wrote:
> Walter Bright wrote:
>
>>> How would I specify that I have a buffer of bytes and I can't change its
>>> location but I can change its contents?
>>
>> You can't. A good question would be what would be the purpose of such?
>
> I pass you a buffer that I've carefully pre-allocated for you to fill
> in. You shouldn't reallocate it but you should modify its contents.
>
> Having the function signature say "takes const-pointer-to-mutable-data"
> makes it clear that the function won't be allocating the buffer for you
> or reallocating it out from under you.
> [...]
> --bb (who was just in the process of writing such a modify-this-buffer
> function in D1, sans const)
Okay, that's a feature.
But wouldn't an assertion do the same for you, just a bit more wordy?
regards, frank
More information about the Digitalmars-d
mailing list