From owner-freebsd-hackers Mon Jun 9 07:52:29 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.5/8.8.5) id HAA25746 for hackers-outgoing; Mon, 9 Jun 1997 07:52:29 -0700 (PDT) Received: from genesis.atrad.adelaide.edu.au (genesis.atrad.adelaide.edu.au [129.127.96.120]) by hub.freebsd.org (8.8.5/8.8.5) with ESMTP id HAA25734 for ; Mon, 9 Jun 1997 07:52:23 -0700 (PDT) Received: (from msmith@localhost) by genesis.atrad.adelaide.edu.au (8.8.5/8.7.3) id AAA29091 for hackers@freebsd.org; Tue, 10 Jun 1997 00:22:21 +0930 (CST) From: Michael Smith Message-Id: <199706091452.AAA29091@genesis.atrad.adelaide.edu.au> Subject: %i conversion in sscanf? To: hackers@freebsd.org Date: Tue, 10 Jun 1997 00:22:20 +0930 (CST) X-Mailer: ELM [version 2.4ME+ PL28 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk Hmm. Beating up on some code here (study break 8) I have an interesting situation where the %i format is not being interpreted as the author of the code I'm munging obviously believed it should. 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()? If not, a question. Is -0x12345678 a legitimate numeric represenatation? If so, how about -0x80000000? It's "fairly" clear that %i might be expected to convert 0xABCDEF45 to a negative number - Tcl thinks that way : silver:/tmp>tclsh % expr 0xABCDEF45 -1412567227 So, a judgement call from the numeric gods, perchance? -- ]] Mike Smith, Software Engineer msmith@gsoft.com.au [[ ]] Genesis Software genesis@gsoft.com.au [[ ]] High-speed data acquisition and (GSM mobile) 0411-222-496 [[ ]] realtime instrument control. (ph) +61-8-8267-3493 [[ ]] Unix hardware collector. "Where are your PEZ?" The Tick [[