4

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
Pascal Cuoq
  • 79,187
  • 7
  • 161
  • 281
user2544482
  • 157
  • 4

2 Answers2

4

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.

byako
  • 3,372
  • 2
  • 21
  • 36
3

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

Jeffrey Scofield
  • 65,646
  • 2
  • 72
  • 108
  • 2
    Unfortunately, this does not work given the type of `Format.sprintf`. `Format.sprintf "%a"` has type `(unit -> '_a -> string) -> '_a -> string` instead of `(Format.formatter -> '_a -> string) -> '_a -> string` – byako Jul 03 '13 at 17:35