[clean-list] Calling C with side effects

John van Groningen johnvg at cs.ru.nl
Mon May 15 12:35:56 MEST 2006


Matthew Bromberg wrote:

>y :: *{#Real}
>y = {1.0, 2.0, 3.0, 4.0}
>
>nlen :: *Int
>nlen = 0
>
>Start :: (*{#Real}, Int)
>Start
>#! nlen = rmac  2.0 x  y
>= (y, nlen)
>
>This code outputs
>({1,2,3,4},4)
>Thus y has not changed and the side effect I was looking for in rmac did not occur even though nlen is
>correctly altered!.

Because y is a function and is called twice in Start. The array created
by the first call to y is modified, but is never printed. Add
	# y=y
to prevent calling y twice.

>..
>
>By the way, I compile this to a .dll, create a symbol file and then link the dll in.  If I attempt to link in routines from other dlls  I always get into trouble, either it can't find them or the link creates an unusable binary. ie if I uncomment the printf statement, the linker can not find printf even though the system libraries should all be on the path;

printf is not a system function, but is part of the C library which
is not linked with Clean programs on windows. To print on the console
from C you can use the following functions in the Clean runtime system:

extern void w_print_char (char c);
extern void w_print_int (int i);
extern void w_print_real (double r);
extern void w_print_string (char *s);
extern void w_print_text (char *s,unsigned long length);

Or call the system function WriteFile.

Kind regards,

John van Groningen


More information about the clean-list mailing list