How-to manipulate a C array with D2 vector operations?

Lars Holowko lars.holowko at gmail.com
Mon Feb 28 15:01:17 PST 2011


On 2/28/2011 10:15 AM, Denis Koroskin wrote:
> On Mon, 28 Feb 2011 19:51:28 +0300, Lars Holowko
> <lars.holowko at gmail.com> wrote:
>
>> gets called from a C module and I cannot change the caller):
>>
>> extern(C) read_into(char *buffer, size_t buf_len);
>>
>> I would like to use D's vector (or array-wise according to TDPL)
>> operations on buffer but I cannot find a way, how I could initialize a
>> (static?) D array and tell it to use buffer as its memory. Obviously I
>
> Here you go:
>
> auto arr = buffer[0..buf_len];
>
> Now you can operate on this array however you like. E.g.
>
> arr[] = 0; // initialize with zeros

Thanks Denis and Trass3r,

that was embarrasingly easy ;-)


More information about the Digitalmars-d-learn mailing list