Go to the first, previous, next, last section, table of contents.
This version of @command{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 @command{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.
- LANG environment
-
This version does not conform to the POSIX standard in the processing
of the LANG environment variable and all environment variables starting
with LC_.
- names
-
Traditional and POSIX @command{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.
- Strings
-
Strings are not allowed to contain NUL characters. POSIX says all characters
must be included in strings.
- last
-
POSIX @command{bc} does not have a \fBlast variable. Some implementations
of @command{bc} use the period (.) in a similar way.
- comparisons
-
POSIX @command{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.
- if statement, else clause
-
POSIX @command{bc} does not have an
else
clause.
- for statement
-
POSIX @command{bc} requires all expressions to be present in the
for
statement.
- &&, ||, !
-
POSIX @command{bc} does not have the logical operators.
- read function
-
POSIX @command{bc} does not have a
read
function.
- print statement
-
POSIX @command{bc} does not have a
print
statement.
- continue statement
-
POSIX @command{bc} does not have a continue statement.
- array parameters
-
POSIX @command{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 @command{bc} have only call by value array parameters.
- function format
-
POSIX @command{bc} requires the opening brace on the same line as the
define
key word and the auto
statement on the next line.
- =+, =-, =*, =/, =%, =^
-
POSIX @command{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.
- spaces in numbers
-
Other implementations of @command{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 @command{bc}.
- errors and execution
-
This implementation varies from other implementations in terms of what
code will be executed when syntax and other errors are found in the
program. If a syntax error is found in a function definition, error
recovery tries to find the beginning of a statement and continue to
parse the function. Once a syntax error is found in the function, the
function will not be callable and becomes undefined.
Syntax errors in the interactive execution code will invalidate the
current execution block. The execution block is terminated by an
end of line that appears after a complete sequence of statements.
For example,
a = 1
b = 2
has 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.
- Interrupts
-
During an interactive session, the SIGINT signal (usually generated by
the control-C character from the terminal) will cause execution of the
current execution block to be interrupted. It will display a "runtime"
error indicating which function was interrupted. After all runtime
structures have been cleaned up, a message will be printed to notify the
user that @command{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 @command{bc}.
Go to the first, previous, next, last section, table of contents.