any news on const/invariant?

Bill Baxter dnewsgroup at billbaxter.com
Mon Nov 26 18:13:53 PST 2007


0ffh wrote:
> 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?

More wordy and not checked at compile time.

But it may be that it's not important enough to warrant language support.

--bb



More information about the Digitalmars-d mailing list