Calling C function with static array includes length and pointer

mwarning moritzwarning at web.de
Mon Jun 21 15:08:15 PDT 2010


On Tue, 22 Jun 2010 00:00:27 +0200, torhu wrote:

> On 21.06.2010 23:30, mwarning wrote:
>> Hi,
>>
>> I try to pass a static array to a variadic C function. Looks like the
>> array is passed by values as expected, but the length and pointer are
>> prepended, too. Is this intentional or a bug?
>>
>> http://pastebin.com/6ejFF37j
> 
> I believe this works as intended.  And arrays in D 1 are *not* passed by
> value, ie. the data is not copied.
> 
>  From www.digitalmars.com/d/1.0/arrays.html:
> 
> "a string literal is passed as a (length,pointer) combination to
> variadic parameters"
Thanks, I missed that section!

> In other words, use stack.ptr if you want just the pointer.
I wrap it into a struct, that will do it.


More information about the Digitalmars-d mailing list