Using "strcpy" to assign value to dynamic char array

Ali Çehreli acehreli at yahoo.com
Mon Nov 1 21:37:59 UTC 2021


On 11/1/21 2:28 PM, pascal111 wrote:

 > This can serve the style I want.

I am feeling funny right now and showing incorrect code. It's impossible 
to fit "Hello World!" in "xyz". As Steve said, don't do that. :)

 > It uses OOP style like C++ by putting a
 > pointer as a property,

D's slices are the equivalent of the following struct (showing for int):

struct __Slice__ {
   size_t length;
   int * ptr;
}

So, .ptr is simply a member variable. (Assigning to .length does some 
magic like allocating more memory in some cases; otherwise it is a 
member variable as well.)

 > but pointers themselves are low level.

arr.ptr is as low as it gets: It is a pointer.

Ali



More information about the Digitalmars-d-learn mailing list