Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 4 Jul 2020 11:50:31 +0200
From:      "Hartmann, O." <o.hartmann@walstatt.org>
To:        Stefan =?ISO-8859-1?Q?E=DFer?= <se@freebsd.org>
Cc:        FreeBSD CURRENT <freebsd-current@freebsd.org>
Subject:   Re: CURRENT: bc -e results in empty string/result
Message-ID:  <20200704115031.5f9ee55c@hermann.fritz.box>
In-Reply-To: <82c80079-2e33-dfea-4553-37806c6fbe60@freebsd.org>
References:  <20200703172503.5b739102@thor.intern.walstatt.dynvpn.de> <82c80079-2e33-dfea-4553-37806c6fbe60@freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
--Sig_/av3=YoL9+Cp2o74+XQe3Sjx
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On Fri, 3 Jul 2020 17:58:27 +0200
Stefan E=C3=9Fer <se@freebsd.org> wrote:

> Am 03.07.20 um 17:24 schrieb O. Hartmann:
> > Hello list,
> >=20
> > running some scripts caluclating via bc() the expression shown
> > below:
> >=20
> > bc -e '6582031 - 1048576 - 0 - 409600 - 1024 - 40 - 4096' -e quit =20
>=20
> The bc in -CURRENT has been replaced by a new implementation.
>=20
> It seems there is one deviation from the behavior of the "old"
> version, in that it executes the "quit" immediately after parsing it.
>=20
> There is a difference between "quit" and "halt", and the following
> command works as expected:
>=20
> $ bc -e '6582031 - 1048576 - 0 - 409600 - 1024 - 40 - 4096' -e halt
> 5118695
>=20
> From the bc man-page:
>=20
>  The quit statement causes bc(1) to quit, even if it is on a branch
> that will not be executed (it is a compile-time command).
>=20
>  The halt statement causes bc(1) to quit, if it is executed. (Unlike
>  quit if it is on a branch of an if statement that is not executed,
>  bc(1) does not quit.)
>=20
> This behavior is identical to that of GNU bc:
>=20
> $ echo "6582031 - 1048576 - 0 - 409600 - 1024 - 40 - 4096; quit " |
> gbc $ echo "6582031 - 1048576 - 0 - 409600 - 1024 - 40 - 4096; halt "
> | gbc 5118695
>=20
> > results on recent CURRENT ( FreeBSD 13.0-CURRENT #80 r362884: Thu
> > Jul  2 10:08:23 CEST 2020 amd64) with an empty result, while it is
> > calculated correctly on 12-STABLE (FreeBSD 12.1-STABLE #67 r362719:
> > Sun Jun 28 09:59:20 CEST 2020 amd64) and a CURRENT dated from  Sun
> > Jun 28th (have no revision number anymore, the expression above was
> > calculated correctly on the same box which now has r362884 and is
> > failing).
> >=20
> > Whats wrong? =20
>=20
> The behavior of the "old" bc in FreeBSD was non-conformant in several
> details, the result of a modulo operation with negative operands was
> the most critical, in my opinion.
>=20
> This is what POSIX says with regard to the "quit" command:
>=20
>  The quit statement ( quit) shall stop execution of a bc program at
> the point where the statement occurs in the input, even if it occurs
> in a function definition, or in an if, for, or while statement.
>=20
> But I'm not sure whether this covers the behavior of GNU bc and this
> new bc, since it does not say, that "quit" will be executed as soon
> as seen by the parser.
>=20
> Regards, STefan


Hello.

Unfortunately, there was no remark in UPDATING and in the hurry I did
not find any traces of the change, so it hit me since several scripts
failed. As a workaround, it helped to replace "-e quit" by "-e halt",
although this might semantically also an unfortunate way to do.

Thanks very much for the fast response,

regards
Oliver

--Sig_/av3=YoL9+Cp2o74+XQe3Sjx
Content-Type: application/pgp-signature
Content-Description: OpenPGP digital signature

-----BEGIN PGP SIGNATURE-----

iHUEARYIAB0WIQSy8IBxAPDkqVBaTJ44N1ZZPba5RwUCXwBQ6AAKCRA4N1ZZPba5
R1F/AQDL7Abkp+QOwsWM1DMnKhKWjyXFIGkgEahNyb3wW3gh9AEAvciCbkTRIQP6
DbKczphSp50pqt3NaXgS2DjLbqdL/gE=
=d0Vi
-----END PGP SIGNATURE-----

--Sig_/av3=YoL9+Cp2o74+XQe3Sjx--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20200704115031.5f9ee55c>