any news on const/invariant?

Walter Bright newshound1 at digitalmars.com
Tue Nov 27 01:53:18 PST 2007


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.



More information about the Digitalmars-d mailing list