将结果放入OCaml中的字符串变量中
我有一个功能,它在offsetmap中打印出值:将结果放入OCaml中的字符串变量中,ocaml,frama-c,Ocaml,Frama C,我有一个功能,它在offsetmap中打印出值: let pretty_offsetmap_original lv fmt offsetmap = begin match offsetmap with | None -> Format.fprintf fmt "<BOTTOM>" | Some off -> let typ = Some (typeOfLval lv) in Format.fprintf fmt "%a%a"
let pretty_offsetmap_original lv fmt offsetmap =
begin match offsetmap with
| None -> Format.fprintf fmt "<BOTTOM>"
| Some off ->
let typ = Some (typeOfLval lv)
in
Format.fprintf fmt "%a%a"
pretty_lval_or_absolute lv
(Cvalue.V_Offsetmap.pretty_typ typ) off
end
似乎需要将
Format.fprintf
替换为Format.sprintf
而不是Printf.sprintf
不幸的是,您是正确的:Format.sprintf
没有正确的类型。在Frama-C中,函数Pretty_utils.sfprintf
将完全满足您的需要。您可能还想看看Pretty\u utils.to\u string
,不幸的是,鉴于Format.sprintf
的类型,这不起作用Format.sprintf“%a”
的类型为(单位->'\u a->string)->'\u a->string
,而不是(Format.formatter->'\u a->string)->'\u a->string
Error: This expression has type
Format.formatter -> Cvalue.V_Offsetmap.t -> unit
but an expression was expected of type unit -> 'a -> string