[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: autoconf macros, portable arithmetic
From: |
Eric Blake |
Subject: |
Re: autoconf macros, portable arithmetic |
Date: |
Thu, 24 Feb 2005 06:02:47 -0700 |
User-agent: |
Mozilla Thunderbird 1.0 (Windows/20041206) |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Asking the list reaches a larger knowledge base than asking one developer.
I think there may already be version comparison macros out there, but I
have not tried searching for one. They probably involve invoking test
multiple times over each version number component, rather than trying to
combine the version components into a single number. But, if you really
want to do it with arithmetic, I think something like this is portable
(provided expr is not implemented with 16-bit math, which would overflow):
`expr $major \* 1000000 + $minor \* 1000 + \$patch`
My original post on the topic was here:
http://lists.gnu.org/archive/html/autoconf/2004-12/msg00180.html
According to Mark Asbach on 2/23/2005 2:24 PM:
> Hi Eric,
>
> searching for portable arithmetic constructs in autoconf macros, I found
> a post of yours ("Proposed doc updates"), that seems to mention, what I
> need:
>
>> address@hidden $((@var{arithmetic}))
>> +Posix specifies that this construct will evaluate its contents as an
>> +arithmetic expression, with the value of the expression being the
>> +result. However, Ash treats this as an undocumented quoting mechanism,
>> +resulting in the literal expression surrounded by 8-bit markers and an
>> +indication of the current quoting level. Likewise, the
>> address@hidden/bin/sh} of Solaris 8 does not support it:
>
>
> However, the necessary details are missing from your post and I couldn't
> find parts of the text anywhere else (searching with Google).
>
> Could you please give me a hint on how to do portable math inside
> autoconf m4 macros? My problem looks simple, but the only solution I
> found was using "$((expression))" constructs, that - as you state - are
> not portable. I have a string containing a dotted version number
> "1.3.23" that I need to compare to some other number like "1.3.20".
> Currently, I split at the dots and then recombine as 1000000*major +
> 1000*minor + subminor, then I can compare with 'test'. But how to do
> that in a portable way?
>
> Mark
>
>
>
- --
Life is short - so eat dessert first!
Eric Blake address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFCHdB384KuGfSFAYARAoxzAJ4qKSVLcMxhXepI+sm8BZcCt6bdyQCfayEy
j6rykJLq9y13eFk4dNln1XA=
=15AA
-----END PGP SIGNATURE-----
- Re: autoconf macros, portable arithmetic,
Eric Blake <=