www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - extern(C) and slices

reply =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
If I have a function like

`extern(C) void f(void *x, size_t x_sz)`

can I instead declare it as

`extern(C) void f(void[] x)`

?
Sep 11 2017
parent reply Jacob Carlborg <doob me.com> writes:
On 2017-09-12 01:03, Nordlöw wrote:
 If I have a function like
 
 `extern(C) void f(void *x, size_t x_sz)`
 
 can I instead declare it as
 
 `extern(C) void f(void[] x)`
 
 ?
It looks like the length needs to come first [1]. I think it would be technically possible if you flipped the parameters but you would become dependent on the ABI as well. I would recommend a wrapper instead. [1] https://dlang.org/spec/abi.html#arrays -- /Jacob Carlborg
Sep 11 2017
parent Per =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
On Tuesday, 12 September 2017 at 06:23:57 UTC, Jacob Carlborg 
wrote:
 It looks like the length needs to come first [1]. I think it 
 would be technically possible if you flipped the parameters but 
 you would become dependent on the ABI as well. I would 
 recommend a wrapper instead.

 [1] https://dlang.org/spec/abi.html#arrays
Thanks.
Sep 12 2017