From owner-freebsd-hackers Mon Jun 9 10:55:44 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.5/8.8.5) id KAA04851 for hackers-outgoing; Mon, 9 Jun 1997 10:55:44 -0700 (PDT) Received: from huset.fm.unit.no (huset.fm.unit.no [129.241.211.212]) by hub.freebsd.org (8.8.5/8.8.5) with SMTP id KAA04846 for ; Mon, 9 Jun 1997 10:55:33 -0700 (PDT) Message-Id: <199706091755.KAA04846@hub.freebsd.org> Received: (qmail 19571 invoked from network); 9 Jun 1997 17:55:09 -0000 Received: from huset.fm.unit.no (HELO stud.math.ntnu.no) (129.241.211.212) by huset.fm.unit.no with SMTP; 9 Jun 1997 17:55:09 -0000 To: msmith@atrad.adelaide.edu.au Cc: hackers@FreeBSD.ORG Subject: Re: %i conversion in sscanf? In-Reply-To: Your message of "Tue, 10 Jun 1997 00:22:20 +0930 (CST)" References: <199706091452.AAA29091@genesis.atrad.adelaide.edu.au> X-Mailer: Mew version 1.06 on Emacs 19.34.1 Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Date: Mon, 09 Jun 1997 19:55:09 +0200 From: Arne Henrik Juul Sender: owner-hackers@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk Michael Smith writes: > To cut a long story short; from sscanf(3) : > > i Matches an optionally signed integer; the next pointer must be a > pointer to int. The integer is read in base 16 if it begins with > `0x' or `0X', in base 8 if it begins with `0', and in base 10 oth- > erwise. Only characters that correspond to the base are used. > > Ok. Fairly ambiguous. Some test examples : > > token: '0x12345678' -> int 0x12345678 > token: '0xABCDEF45' -> int 0x7fffffff > > Hmm. Not _necessarily_ expected, although it makes reasonable sense. > However, what I wonder is is this "right" by whatever standard governs > sscanf()? ANSI C mandates that scanf %i should work like strtol() with base=0; which again should work the same way that integer constants in the code does (but with an optional preceding plus or minus sign). Then it goes on (for strtol) to say: "If the correct value is outside the range of representable values, LONG_MAX or LONG_MIN is returned (according to the sign of the value), and the value of the macro ERANGE is stored in errno." I take a wild guess your application really wanted to use strtoul(), which isn't available everywhere (though it's in ANSI C so it should be common). - Arne H. J.