From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 9050ABC69 for ; Wed, 27 Jun 2007 06:11:05 +0200 (CEST) Received: from sccmmhc91.asp.att.net (sccmmhc91.asp.att.net [204.127.203.211]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l5R4B4mP014783 for ; Wed, 27 Jun 2007 06:11:05 +0200 Received: from [192.168.0.104] (12-208-242-210.client.mchsi.com[12.208.242.210]) by sccmmhc91.asp.att.net (sccmmhc91) with SMTP id <20070627041104m9100d3cp1e>; Wed, 27 Jun 2007 04:11:04 +0000 In-Reply-To: <86507DD0-1BCB-4BF9-A058-0809022E564C@lrde.epita.fr> References: <0AC5F6BF-D076-4561-B015-70E41954D248@lrde.epita.fr> <7A72D27B-4FF3-4483-8D42-B9904FA734E2@valdosta.edu> <86507DD0-1BCB-4BF9-A058-0809022E564C@lrde.epita.fr> Mime-Version: 1.0 (Apple Message framework v752.3) Content-Type: text/plain; charset=ISO-8859-1; delsp=yes; format=flowed Message-Id: <8503CBAB-EF9E-4CF0-89A8-2F6E454CF4DC@valdosta.edu> Cc: caml-list@inria.fr Content-Transfer-Encoding: quoted-printable From: Jonathan Bryant Subject: Re: [Caml-list] precision not working properly for strings in Printf? Date: Wed, 27 Jun 2007 00:11:01 -0400 To: =?ISO-8859-1?Q?Qu=F4c_Peyrot?= X-Mailer: Apple Mail (2.752.3) X-Miltered: at concorde with ID 4681E358.001 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; printf:01 printf:01 const:01 pointer:01 pointer:01 terminating:01 terminating:01 ocaml:01 scanf:01 ocaml:01 compiler:01 wrappers:01 specifier:01 beginner's:01 bug:01 On Jun 26, 2007, at 11:48 PM, Qu=F4c Peyrot wrote: > > On Jun 27, 2007, at 5:38 AM, Jonathan Bryant wrote: > >> >> On Jun 26, 2007, at 11:18 PM, Qu=F4c Peyrot wrote: >> >>> It seems that the precision field doesn't work properly with the =20 >>> "s" type in Printf.printf: >> >> It does work properly. It's just not working the way you're =20 >> expecting it to work. > > I was just expecting it to work like the printf from the glibc: > > s If no l modifier is present: The const char * =20 > argument is > expected to be a pointer to an array of character type =20= > (pointer > to a string). Characters from the array are written up = to =20 > (but > not including) a terminating NUL character; if a =20 > precision is > specified, no more than the number specified are written. = =20 > If a > precision is given, no null character need be present; = if =20 > the > precision is not specified, or is greater than the size = of =20 > the > array, the array must contain a terminating NUL character. The OCaml standard library isn't glibc. The implementation of the =20 Printf/Scanf modules is custom, OCaml specific and tied into the =20 compiler, so one should not assume the behave the same way. They are =20= not simply wrappers. As a matter of fact, they have several other =20 differences from the glibc printf family of functions (look at the =20 conversion specifiers in the docs). > >>> # Printf.printf "%.2s" "qwerty";; >>> qwerty- : unit =3D () >>> >>> This should print "qw" >> >> No it shouldn't. The width/precision specifier guarantees a =20 >> _minimum_ length for strings, not an absolute length. =46rom the =20 >> docs for Printf: > > As said above, this is not how printf is working in the glibc (at =20 > least on linux and Mac OS X). Any clue why the same convention has =20 > not been followed? See above. > > --=20 > Best Regards, > Qu=F4c > > > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs