我有这个功能工作,它打印出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"
pretty_lval_or_absolute lv
(Cvalue.V_Offsetmap.pretty_typ typ) off
end
现在我想将值输入到字符串变量中以便为我的目的进行转换。我将Format.fprintf fmt
替换为Printf.sprintf
,但它不起作用。编译错误:
Error: This expression has type
Format.formatter -> Cvalue.V_Offsetmap.t -> unit
but an expression was expected of type unit -> 'a -> string
答案 0 :(得分:4)
不幸的是,你是对的:Format.sprintf
没有好的类型。在Frama-C中,函数Pretty_utils.sfprintf
将完全满足您的需求。您可能还想查看Pretty_utils.to_string
。
答案 1 :(得分:3)
您似乎需要将Format.fprintf
替换为Format.sprintf
而不是Printf.sprintf
。