bc
and Other Implementations
This version of bc
was implemented from the POSIX P1003.2/D11
draft and contains several differences and extensions relative to the
draft and traditional implementations. It is not implemented in the
traditional way using dc
. This version is a single process
which parses and runs a byte code translation of the program. There is
an "undocumented" option (-c) that causes the program to output the byte
code to the standard output instead of running it. It was mainly used
for debugging the parser and preparing the math library.
A major source of differences is extensions, where a feature is extended to add more functionality and additions, where new features are added. The following is the list of differences and extensions.
bc
have single letter names for functions, variables and arrays. They have
been extended to be multi-character names that start with a letter and
may contain letters, numbers and the underscore character.
bc
does not have a \fBlast variable. Some implementations
of bc
use the period (.) in a similar way.
bc
allows comparisons only in the if
statement,
the while
statement, and the second expression of the for
statement. Also, only one relational operation is allowed in each of
those statements.
bc
does not have an else
clause.
bc
requires all expressions to be present in the
for
statement.
bc
does not have the logical operators.
bc
does not have a read
function.
bc
does not have a print
statement.
bc
does not have a continue statement.
bc
does not (currently) support array parameters in full.
The POSIX grammar allows for arrays in function definitions, but does
not provide a method to specify an array as an actual parameter. (This
is most likely an oversight in the grammar.) Traditional implementations
of bc
have only call by value array parameters.
bc
requires the opening brace on the same line as the
define
key word and the auto
statement on the next line.
bc
does not require these "old style" assignment
operators to be defined. This version may allow these "old style"
assignments. Use the limits
statement to see if the installed
version supports them. If it does support the "old style" assignment
operators, the statement "a =- 1" will decrement a
by 1 instead
of setting a
to the value -1.
bc
allow spaces in numbers. For example,
"x=1 3" would assign the value 13 to the variable x. The same statement
would cause a syntax error in this version of bc
.
a = 1 b = 2has two execution blocks and
{ a = 1 b = 2 }has one execution block. Any runtime error will terminate the execution of the current execution block. A runtime warning will not terminate the current execution block.
bc
is ready for more input. All previously defined
functions remain defined and the value of all non-auto variables are the
value at the point of interruption. All auto variables and function
parameters are removed during the clean up process. During a
non-interactive session, the SIGINT signal will terminate the entire run
of bc
.
Go to the first, previous, next, last section, table of contents.