[clean-list] Calling C with side effects

Matthew Bromberg mattcbro at earthlink.net
Wed May 31 22:12:30 MEST 2006


WriteFile or better the stream libraries are just fine, however the only 
way to format a Real type into text, that I've currently found is
to use toString.  Imagine therefore trying to print out, say exp(20) in 
8 characters or less.  It requires exponential notation.
That's why I found myself longing for a printf function to format 
floating point numbers and print to the console. Are there
any other functions available for producing formatted floating point?


John van Groningen wrote:
> 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