From owner-freebsd-bugs@FreeBSD.ORG Wed Jul 10 09:10:01 2013 Return-Path: Delivered-To: freebsd-bugs@smarthost.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id ADFEE7DD for ; Wed, 10 Jul 2013 09:10:01 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) by mx1.freebsd.org (Postfix) with ESMTP id 869821D84 for ; Wed, 10 Jul 2013 09:10:01 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.7/8.14.7) with ESMTP id r6A9A1xb049179 for ; Wed, 10 Jul 2013 09:10:01 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.7/8.14.7/Submit) id r6A9A1mq049178; Wed, 10 Jul 2013 09:10:01 GMT (envelope-from gnats) Date: Wed, 10 Jul 2013 09:10:01 GMT Message-Id: <201307100910.r6A9A1mq049178@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: Steffen "Daode" Nurpmeso Subject: Re: bin/180328: awk(1) fails to treat var as integer X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: Steffen Daode Nurpmeso List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Jul 2013 09:10:01 -0000 The following reply was made to PR bin/180328; it has been noted by GNATS. From: Steffen "Daode" Nurpmeso To: bug-followup@FreeBSD.org Cc: Subject: Re: bin/180328: awk(1) fails to treat var as integer Date: Wed, 10 Jul 2013 11:01:34 +0200 Hello, i'm forwarding one more. (This time to bug-followup@ -- hello, Mark Linimon!) -------- Original Message -------- Date: Wed, 10 Jul 2013 10:53:13 +0200 From: Steffen "Daode" Nurpmeso To: gnats-bugs@NetBSD.org Subject: Re: bin/48017: awk(1) fails to treat var as integer (may be related to #47840) David Holland wrote: | sprintf witih %d doesn't produce an number value; it produces a | string value, which you have to coerce to a number by adding zero to | it to get it to behave like a number. (Adding +0 was my final solution too, because GNU awk(1) didn't make it by the (presumably more expensive, too) sprintf("%X") call just as all other tested awk(1)s did.) So there is a problem with the implicit type conversion, since echo f001 f00d |\ awk '{ a=sprintf("%d", "0x" $1); b=sprintf("%d", "0x" $2); while (a < b) { print a; a++; }}' works just fine?!? I think the relevant parts from POSIX are the value of an expression shall be implicitly converted to the type needed for the context in which it is used. [.] A numeric value that is exactly equal to the value of an integer (see Concepts Derived from the ISO C Standard) shall be converted to a string by the equivalent of a call to the sprintf function (see String Functions) with the string "%d" as the fmt argument and the numeric value being converted as the first and only expr argument. [.] This volume of POSIX.1-2008 specifies no explicit conversions between numbers and strings. An application can force an expression to be treated as a number by adding zero to it, or can force it to be treated as a string by concatenating the null string ( "" ) to it. [.] A string value shall be considered a numeric string if it comes from one of the following: [.] 1. Field variables [.] 8. Variable assignment from another numeric string variable [...] and an implementation-dependent condition corresponding to either case (a) or (b) below is met. [.] b. After all the following conversions have been applied, the resulting string would lexically be recognized as a NUMBER token as described by the lexical conventions in Grammar : [.] Whether or not a string is a numeric string shall be relevant only in contexts where that term is used in this section. And because the `Table: Expressions in Decreasing Precedence in awk' contains the line expr < expr Less than Numeric None i believe its a bug. (That hopefully gets fixed by someone who yet has some experience with the awk codebase.) | David A. Holland | dholland@netbsd.org --steffen