[cffi-devel] vararg (was: CFFI/CLISP - 2 out of 101 total tes ts f ailed)

Yaroslav Kavenchuk kavenchuk at jenty.by
Thu Jan 5 09:54:19 UTC 2006


Yaroslav Kavenchuk wrote:

> Hmm, sprintf under mingw not work with double/single-float without any
> varargs:
> 
> check:
> 
> (ffi:def-call-out sprintf-int (:name "sprintf") (:return-type nil)
>   (:library :default) (:language :stdc)
>   (:arguments
>     (out-str (ffi:c-ptr (ffi:c-array-max character 256)) :out :alloca)
>     (fmt ffi:c-string) (n ffi:int)))
> SPRINTF-INT
> (sprintf-int "%d" 100)
> "100"
> 
> double:
> 
> (ffi:def-call-out sprintf-double (:name "sprintf") (:return-type nil)
>   (:library :default) (:language :stdc)
>   (:arguments
>     (out-str (ffi:c-ptr (ffi:c-array-max character 256)) :out :alloca)
>     (fmt ffi:c-string) (n ffi:double-float)))
> SPRINTF-DOUBLE
> (sprintf-double "%.2f" 3.14d0)
> "X\""
> 
> Perhaps, reason in it?
> 
> Thanks!
> 

Oops, if use libintl_sprintf instead of sprintf - all works:

[5]> (ffi:def-call-out li-sprintf-double (:name "libintl_sprintf")
  (:return-type nil) (:library :default) (:language :stdc)
  (:arguments
    (out-str (ffi:c-ptr (ffi:c-array-max character 256)) :out :alloca)
    (fmt ffi:c-string) (n ffi:double-float)))
LI-SPRINTF-DOUBLE
[6]> (li-sprintf-double "%.2lf" 3.14d0)
"3.14"
[7]> (li-sprintf-double "%.2f" 3.14d0)
"3.14"

Hmm. I do not know why sprintf function does not work in clisp/mingw.

Thanks!

-- 
WBR, Yaroslav Kavenchuk.



More information about the cffi-devel mailing list