将结果输入OCaml中的字符串变量

时间:2013-07-02 22:41:38

标签: 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"
      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

2 个答案:

答案 0 :(得分:4)

不幸的是,你是对的:Format.sprintf没有好的类型。在Frama-C中,函数Pretty_utils.sfprintf将完全满足您的需求。您可能还想查看Pretty_utils.to_string

答案 1 :(得分:3)

您似乎需要将Format.fprintf替换为Format.sprintf而不是Printf.sprintf