any news on const/invariant?
Sean Kelly
sean at f4.ca
Tue Nov 27 11:03:09 PST 2007
Walter Bright wrote:
> Sean Kelly wrote:
>> Walter Bright wrote:
>>> Regan Heath wrote:
>>>> 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?
>>>
>>> No. foo() modifies its copy of pbuffer, which is not the same as buffer.
>>
>> So we'll have pass by value for arrays? Nifty.
>
> Arrgh! There are two things here, the length/ptr, and the array
> contents. The former is passed by value.
Oops! I totally misunderstood. This is yet another reminder of why I
try to avoid posting so early in the morning. One of these days the
lesson will sink in.
Sean
More information about the Digitalmars-d
mailing list