16.12.2012 Views

z/OS V1R9.0 UNIX System Services Command ... - Christian Grothoff

z/OS V1R9.0 UNIX System Services Command ... - Christian Grothoff

z/OS V1R9.0 UNIX System Services Command ... - Christian Grothoff

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

|<br />

|<br />

bc<br />

Usage notes<br />

Files<br />

Localization<br />

1. Unlike the C language, which uses lexical scoping rules, bc uses dynamic<br />

scoping, which is most easily explained with an example:<br />

a=10<br />

define f1() {<br />

auto a;<br />

a = 13;<br />

return (f2())<br />

}<br />

define f2() {<br />

return (a)<br />

}<br />

f1()<br />

13<br />

f2()<br />

10<br />

If f1() is called, bc prints the number 13, instead of the number 10. This is<br />

because f1() hides away the old (global) value of a and then sets it to 13. When<br />

f2() refers to a, it sees the variable dynamically created by f1() and so prints 13.<br />

When f1() returns, it restores the old value of a. When f2() is called directly,<br />

instead of through f1(), it sees the global value for a and prints 10. The<br />

corresponding C code prints 10 in both cases.<br />

2. Numbers are stored as strings in the program and converted into numbers each<br />

time they are used. This is important because the value of a “constant” number<br />

may change depending on the setting of the ibase variable. For example,<br />

suppose the following instructions are given to bc:<br />

define ten() {<br />

return (10)<br />

}<br />

ten()<br />

10<br />

ibase=16<br />

ten()<br />

16<br />

In this example, when the base is set to 10, ten() returns the decimal value 10.<br />

However, when the input base is changed to 16, the function returns the<br />

decimal value 16. This can be a source of confusing errors in bc programs.<br />

3. The library of functions loaded using the –l option is stored in the file<br />

/usr/lib/lib.b under your root directory. This is a simple text file that you can<br />

examine and change to add new functions as desired.<br />

4. In a noninteractive invocation, bc will exit on any invalid input and the rest of<br />

the input will be skipped.<br />

bc uses the following file:<br />

/usr/lib/lib.b<br />

File containing the library of functions loaded with –l<br />

bc uses the following localization environment variables:<br />

v LANG<br />

v LC_ALL<br />

v LC_CTYPE<br />

v LC_MESSAGES<br />

v LC_SYNTAX<br />

64 z/<strong>OS</strong> <strong>V1R9.0</strong> <strong>UNIX</strong> <strong>System</strong> <strong>Services</strong> <strong>Command</strong> Reference

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!