09.06.2013 Views

Intel XENIX 286 Programmers Guide (86) - Tenox.tc

Intel XENIX 286 Programmers Guide (86) - Tenox.tc

Intel XENIX 286 Programmers Guide (86) - Tenox.tc

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

m4: Macro Processor <strong>XENIX</strong> Programm ing<br />

Leading unquoted blanks, tabs, or newlines that occur during argument collection are<br />

discarded. All other white space is retained. Thus<br />

defi ne(a, b c)<br />

defines a to be "b c".<br />

Arguments are separated by commas, but parentheses are counted properly, so a comma<br />

protected by parentheses does not terminate an argument. That is, in<br />

defi ne(a, (b,c))<br />

there are only two arguments; the second is literally "(b,c)". Note that a bare comma or<br />

parenthesis can be inserted by quoting it.<br />

Using Arithmetic Built-In Macros<br />

m4 provides two built-in macros for doing arithmetic on integers. The simplest is incr,<br />

which increments its numeric argument by 1. Thus, to handle the common programming<br />

situation where you want a variable to be defined as one more than N, write<br />

defi ne(N, 1 00)<br />

define(N 1, 'incr(N)')<br />

The more general mechanism for arithmetic is a built-in macro called eval, which is<br />

capable of arbitrary arithmetic on integers. It provides the following operators (in<br />

decreasing order of precedence):<br />

unary + and -<br />

** or " (exponentiation)<br />

* I % (modulus)<br />

+ -<br />

= = ! = < < = > > =<br />

(not)<br />

& or && {logical and)<br />

I or I I {logical or)<br />

Parentheses may be used to group operations where needed. All the operands of an<br />

expression given to eval must ultimately be numeric. The numeric value of a true<br />

relation (like 1> O) is 1 and of a false relation is 0. The precision in eval is<br />

implementation dependent.<br />

As a simple example, suppose we want M to have the numeric value 2**N+ 1. Then we<br />

could write:<br />

define(N, 3)<br />

define(M, 'eval(2** N + 1 ) ')<br />

As a matter of principle, it is advisable to quote the defining text for a macro unless it<br />

is very simple indeed (e.g., just a nu mber); it usually gives the result you want and is a<br />

good habit to get into.<br />

11-6

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

Saved successfully!

Ooh no, something went wrong!