bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: compat vs posix modes


From: Aharon Robbins
Subject: Re: compat vs posix modes
Date: Thu, 04 Mar 2010 20:54:55 +0200

Hi.

> Date: Wed, 3 Mar 2010 13:28:10 -0800 (PST)
> From: Janos Barbero <address@hidden>
> To: address@hidden
> Subject: compat vs posix modes
>
> Hello,
>
> GNU awk's compatibility mode does not seem to include the
> -Wnon-decimal-data option:
>    $ echo 0x5 | gawk -Wtraditional '{printf "%d\n", $1}'
>    0
>    $ echo 0x5 | gawk -Wnon-decimal-data '{printf "%d\n", $1}'
>    5
>
> POSIX mode does include this, so I may just be misunderstanding the
> manual.
>    $ echo 0x5 | gawk -Wposix '{printf "%d\n", $1}'
>    5
>
> man:
> --traditional
>         Run in compatibility mode.  In compatibility mode, gawk behaves
>         identically to UNIX awk; none of the GNU-specific extensions
>         are recognized.  The use of --traditional is preferred over
>         the other forms of this option.  See GNU EXTENSIONS, below,
>         for more information.
>
> Kernighan's awk does interpret hex data. On my Debian system, Kernighan's
> awk is called original-awk, so:
>    $ echo 0x5 | original-awk '{printf "%d\n", $1}'
>    5
>
> Sorry if I am wasting your time with a design question, I just thought
> it might be a bug.
>
> For reference, versions are as follows:
> GNU Awk 3.1.6
> gcc (Debian 4.3.2-1.1) 4.3.2
>
> Thank you,
> Janos

This is discussed in:

http://www.gnu.org/software/gawk/manual/gawk.html#POSIX-Floating-Point-Problems

The upshot is that Kernighan's awk just uses strtod without any
qualms. strtod on glibc systems understands a hexadecimal version of
floating point and thus converts the value.  If you compile his awk on an
older system or some other that doesn't do hexadecimal floating point,
you will get a different result.  Thus the "support" is by accident and
not by design.

On the other hand, I argue that this is not what is right for awk or gawk,
and so I go to more trouble to prevent this kind of thing.  HOWEVER,
there are people who claim otherwise, and thus in POSIX mode gawk simply
relies on strtod ("hands off").  It's a compromise for a messy situation.

Thanks,

Arnold




reply via email to

[Prev in Thread] Current Thread [Next in Thread]