www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - q about bindings to C (noob)

reply RomanZ <rommmmm ya.ru> writes:
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
parent reply Jacob Carlborg <doob me.com> writes:
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
parent RomanZ <zrrole ya.ru> writes:
thanks.
Aug 03 2016