Subject: Re: m4 question
To: Thomas Klausner <wiz@netbsd.org>
From: Klaus Klein <kleink@mibh.de>
List: current-users
Date: 10/05/2005 19:56:10
Thomas Klausner wrote:

> Under current (and all releases back to 1.6.2), m4 does the following:
> 
> $ echo 'eval(5 & 15)' | m4
> 1
> 
> I would have expected the result to be the bitwise AND of 5 and
> 15, which is 5 AFAIK. I get this result with GNU m4-1.4.3.
> 
> I can get it to produce 0 by checking 0&0, but all
> positive values I tried produce 1.
> 
> Is this a bug in m4?

In a way.  The bitwise operators appeared (as far as I can tell)
in System V while switching artithmetic over to C's, which has
been picked up by POSIX since.  For the rest of the story, see
expr.c rev. 1.6.

This ought to be fixed at least to some extent (I noticed that
in two popular implementations, namely GNU M4 and the SunOS one,
the precedence of ! doesn't match the standard); the question is
whether (and if so, how) compatibility issues with K&R M4 need to
be addressed, depending on the extent of the change.  (I don't
anticipate problems with making the bitwise-op change in place,
but I'd keep clear of increasing !'s precedence.)


- Klaus

P.S. You can find the K&R manual in PSD:17.