[Haskell-cafe] howto c2hs marshall in out argument by reference

Marc Weber marco-oweber at gmx.de
Tue Dec 19 16:31:26 EST 2006

The function takes a pointer to an integer, prints its value and returns the increment.
	void cl_inc(int *i){
	    printf("changing int from %d to %d", *i, (++i));

I've managed it by using this code:

	{#fun pure cl_inc
			{alloca `CInt' peek*} 
			-> `()'#}
and calling it this way:
	alloca $ \mem -> do poke mem 3; print_int_ptr_value mem

then its a matter of reading mem by using peak again.

Is there a better way letting {#func  do the marshalling to be able to do directly?
	print $ cl_inc 3

More information about the Haskell-Cafe mailing list