|
From: | Lee Howard |
Subject: | Re: [gawk] type conversion error ascii (hex) to integer |
Date: | Tue, 16 Aug 2005 09:00:53 -0700 |
User-agent: | Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040731 |
Stepan Kasal wrote:
Hello, On Tue, Aug 16, 2005 at 07:59:06AM -0700, Lee Howard wrote:awk 'BEGIN { printf(strtonum("0xff")) "\n" };'...Unfortunately, neither --non-decimal-data nor strtonum are portable.Sure, there is no portable solution. It was shere good luck if your solution worked on more platforms. POSIX prohibits hexadecimal numbers even in program code.
It was a somewhat recent development and had only been tested thoroughly with mawk 1.3.3 and gawk 3.0.6. The problem was noticed with gawk 3.1.3. I suspect that it would have been a problem on other awk implementations, yes. So I've been looking for a portable solution, and I didn't mean to indicate that the original implementation was portable (because it obviously wasn't).
But strtonum can be implemented as a user function; actually, it comes as an example with gawk. It's installed as /usr/share/awk/strtonum.awk on my GNU/Linux system.
I ended up writing a user function that converted ascii (hex-representation) to a number, and that works fine for me. I thought that I had encountered a bug, so I reported it here out of diligence. I see now that it was a feature and not a bug, so I apologize for the error.
Thanks, Lee.
[Prev in Thread] | Current Thread | [Next in Thread] |