digitalmars.D.learn - q about bindings to C (noob)
- RomanZ (12/12) Aug 03 2016 version(RefOut)
- Jacob Carlborg (8/19) Aug 03 2016 It should work. It depends on how close you would like the D code to be
- RomanZ (1/1) Aug 03 2016 thanks.
version(RefOut) extern(C) void fun(out int input, ref in output); else extern(C) void fun( /*[out]*/ int* input, const(float)* output); version = RefOut; void main() { int input; float output; fun( input, output ); // work fine; is it correct binding? or where the trouble? }
Aug 03 2016
On 2016-08-03 10:27, RomanZ wrote:version(RefOut) extern(C) void fun(out int input, ref in output); else extern(C) void fun( /*[out]*/ int* input, const(float)* output); version = RefOut; void main() { int input; float output; fun( input, output ); // work fine; is it correct binding? or where the trouble? }It should work. It depends on how close you would like the D code to be to the C code. For example, the C code requires to pass pointers where in the D code this will handled automatically. Note also that "out" parameters are automatically reset to there .init value when passed to a function. -- /Jacob Carlborg
Aug 03 2016