Strange appender behavior

Adam D. Ruppe destructionator at gmail.com
Wed Mar 13 13:42:02 UTC 2019


On Wednesday, 13 March 2019 at 13:03:27 UTC, tchaloupka wrote:
> Is this expected?:

You never called the constructor, which means it was lazy 
initialized... but that was done inside one of the functions, 
which received the Appender by value.

So when it set its internal pointer, it was inside a function and 
never got seen outside. Similar to if you do

char* a;
void foo(char* a) {
      a = new char[](10);
}

foo(a);


If you were to put something before the other calls, it would 
work. Or call the constructor (which the little-a appender 
function does).

I'm kinda of the opinion this should be a compile error; that it 
should force you to call the constructor, so that could be a 
minor bug, but it isn't unexpected per se since regular pointers 
and arrays work the same way.


More information about the Digitalmars-d-learn mailing list