Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 3 Jul 2020 17:58:27 +0200
From:      =?UTF-8?Q?Stefan_E=c3=9fer?= <se@freebsd.org>
To:        "O. Hartmann" <ohartmann@walstatt.org>, FreeBSD CURRENT <freebsd-current@freebsd.org>
Subject:   Re: CURRENT: bc -e results in empty string/result
Message-ID:  <82c80079-2e33-dfea-4553-37806c6fbe60@freebsd.org>
In-Reply-To: <20200703172503.5b739102@thor.intern.walstatt.dynvpn.de>
References:  <20200703172503.5b739102@thor.intern.walstatt.dynvpn.de>

next in thread | previous in thread | raw e-mail | index | archive | help
Am 03.07.20 um 17:24 schrieb O. Hartmann:
> Hello list,
> 
> running some scripts caluclating via bc() the expression shown below:
> 
> bc -e '6582031 - 1048576 - 0 - 409600 - 1024 - 40 - 4096' -e quit

The bc in -CURRENT has been replaced by a new implementation.

It seems there is one deviation from the behavior of the "old" version,
in that it executes the "quit" immediately after parsing it.

There is a difference between "quit" and "halt", and the following
command works as expected:

$ bc -e '6582031 - 1048576 - 0 - 409600 - 1024 - 40 - 4096' -e halt
5118695

>From the bc man-page:

 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).

 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.)

This behavior is identical to that of GNU bc:

$ echo "6582031 - 1048576 - 0 - 409600 - 1024 - 40 - 4096; quit " | gbc
$ echo "6582031 - 1048576 - 0 - 409600 - 1024 - 40 - 4096; halt " | gbc
5118695

> 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).
> 
> Whats wrong?

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.

This is what POSIX says with regard to the "quit" command:

 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.

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.

Regards, STefan



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?82c80079-2e33-dfea-4553-37806c6fbe60>