Вопрос

I have this function working which prints out the value in an 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

Now I would like to get the value in to a string variable to transform it for my purpose. I replaced Format.fprintf fmt by Printf.sprintf but it does not work. The compiling error:

Error: This expression has type
      Format.formatter -> Cvalue.V_Offsetmap.t -> unit
    but an expression was expected of type unit -> 'a -> string
Это было полезно?

Решение

Unfortunately, you are correct: Format.sprintf does not have the good type. Within Frama-C, the function Pretty_utils.sfprintf will do exactly what you need. You may also want to have a look at Pretty_utils.to_string.

Другие советы

Seems like you'd need to replace Format.fprintf with Format.sprintf not with Printf.sprintf.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top