any news on const/invariant?
Regan Heath
regan at netmail.co.nz
Tue Nov 27 01:32:07 PST 2007
Walter Bright 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.
>
> Then just pass in the buffer[]. No need to pass *buffer* by reference.
void foo(char[] pbuffer)
{
//assume this causes reallocation
//assume there is no more space in place
pbuffer ~= "a";
}
void main()
{
char[] buffer = "test".dup;
foo(buffer);
buffer[0] = 'a' //crash
}
Right?
Regan
More information about the Digitalmars-d
mailing list