From owner-freebsd-questions Fri May 17 14:28:18 2002 Delivered-To: freebsd-questions@freebsd.org Received: from chen.org.nz (chen.org.nz [210.54.19.51]) by hub.freebsd.org (Postfix) with ESMTP id C204037B406 for ; Fri, 17 May 2002 14:28:13 -0700 (PDT) Received: from grimoire.chen.org.nz (localhost [127.0.0.1]) by chen.org.nz (8.12.3/8.12.3) with ESMTP id g4HLSCZk085668; Sat, 18 May 2002 09:28:12 +1200 (NZST) (envelope-from jonc@grimoire.chen.org.nz) Received: (from jonc@localhost) by grimoire.chen.org.nz (8.12.3/8.12.3/Submit) id g4HLSCQJ085667; Sat, 18 May 2002 09:28:12 +1200 (NZST) (envelope-from jonc) Date: Sat, 18 May 2002 09:28:12 +1200 From: Jonathan Chen Cc: "Terry R. Friedrichsen" , questions@FreeBSD.ORG Subject: Re: printf(3) problem? Message-ID: <20020518092812.B85520@grimoire.chen.org.nz> References: <200205171038.DAA52246@uplift.sunquest.com> <20020518091648.A85520@grimoire.chen.org.nz> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5.1i In-Reply-To: <20020518091648.A85520@grimoire.chen.org.nz>; from jonc@chen.org.nz on Sat, May 18, 2002 at 09:16:48AM +1200 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Sat, May 18, 2002 at 09:16:48AM +1200, Jonathan Chen wrote: > On Fri, May 17, 2002 at 03:38:18AM -0700, Terry R. Friedrichsen wrote: > > > > > > I've never tried this before, so I may simply be doing it wrong. I'm using > > FreeBSD 4.5-RELEASE, and the following program appears to print the wrong > > thing. I'm somewhat buoyed by the fact that Tru64 and Linux agree with me. > > > > My belief is that the correct output of this program should be: > > > > p1,p2 = 00000000000000012345,00000000000000067890 > > > > but FreeBSD prints instead: > > > > p1,p2 = 00000000000000012345,20 > > > > Have I missed something here? > > > > I happen to agree with you; you may want to sendpr(1) your > observations. Sigh. On a second review, the problem here is that you're supplying an "int" sized value when the format string expects a "long" sized value. ie: if you change the type of p1 and p2 to unsigned long p1, p2; you'll find that the results come out as expected. ie the behaviour of printf(3) is correct, after all. Cheers. -- Jonathan Chen ---------------------------------------------------------------------- "Only the meek get pinched. The bold survive." - Ferris Bueller > > --------------------------------------cut here--------------------------- > > #include > > #include > > > > #include > > > > #define ULONG_LEN (size_t)20 > > > > > > > > main() > > > > { > > off_t p1, p2; > > > > p1 = 12345; p2 = 67890; > > > > printf("p1,p2 = %0*lu,%0*lu\n", ULONG_LEN, p1, ULONG_LEN, p2); > > > > exit(0); > > } To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message