English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Re: [Caml-list] sprintf-Bug?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-02-04 (10:04)
From: David Allsopp <dra-news@m...>
Subject: Re: [Caml-list] sprintf-Bug?
> > Oliver Bandel wrote:
> But why didn't worked the code with the two sprintf's?!
> The outer sprintf should have do what I was looking for?!

Printf.sprintf "%0X" converts a number to a capitalised hex *string* (the 0
is pointless without a width specification --- there will never be padding)

Printf.sprintf "%02s" inserts a *string* ensuring that it is at least two
characters long. The '0' is ignored --- the O'Caml manual states that the
'0' and '+' flags are for numerical conversion only
(http://caml.inria.fr/pub/docs/manual-ocaml/libref/Printf.html). I guess you
could argue that "%02s" is not a valid format and so should raise 

This is also the behaviour of ISO C sprintf

> Thanks,
>    Oliver