Each message string is explicitly defined as a compound_string in the UIL module. The UIL compiler only
converts a NULL−terminated string to a compound_string when it is assigned to an XmString resource.
25.3.3 Numeric Values
UIL supports several numeric value types, specifically integers, booleans, floating point values, and integer arrays. In
addition, UIL understands C−like numeric expressions and lets you explicitly convert numeric values from one type to
another. Let's begin by looking at UIL integer values. The following fragment illustrates how you can define integer
variables and set widget resources to integer values:
value
spacing : 5;
font_size : exported −2;
object rc : XmRowColumn {
arguments {
XmNmarginWidth = 3;
XmNspacing = spacing;
};
};
Unlike in C, the boolean type is built into UIL. You represent boolean values with the the reserved keywords
true, false, on and off, as shown in the following code fragment:
value
alive : true;
debug : exported true;
object button : XmPushButton {
arguments {
XmNwidth = 100;
XmNrecomputeSize = false;
XmNsensitive = alive;
XmNtraversalOn = off;
};
};
The keywords true and on both represent true values, while false and off are both false values.
Although none of the Motif widgets use floating point resources, UIL provides support for floating point values.
Floating point values must contain a decimal point so that the UIL compiler can distinguish them from integers. The
following code fragment shows a value section that defines several floating point variables:
value
pi : 3.14159;
Avogadro: exported 6.023e23;
slope : −3.3337;
millisecond: 1e−3;
Floating point values can be defined both with and without exponents. A floating point value defined in UIL is stored
as a C double. Although you probably won't use floats very often, some potential uses include setting resources of
user−defined widgets, exporting them back to the application, and passing them as callback arguments. Even though
UIL is a static description language, you can use numeric expressions that are very similar to C expressions.
Expressions in UIL are evaluated at compile−time, not at run−time. UIL supports the standard operators for use with
integer, floating point, and boolean values. summarizes these operators and their precedence order. As with C, you can
25 Creating a User Interface With UIL 25.3.3 Numeric Values
674
add parentheses to change the order of evaluation.
lp9 | lp9 | lp9 | lp9 | lp9 lp9 | lp9 | lp9 | lp9 | lp9. Operator Type Operand Types Operation Precedence
_
~ unary boolean NOT 1 (highest) integer One's complement 1 unary integer Negation 1 float Negation 1 + unary
integer None 1 float None 1 * binary integer Multiplication 2 float Multiplication 2 / binary integer Division 2 float
Division 2 + binary integer Addition 3 float Addition 3 binary integer Subtraction 3 float Subtraction 3 >> binary
integer Shift right 4 << binary integer Shift left 4 & binary boolean AND 5 integer Bitwise AND 5 | binary boolean
OR 6 integer Bitwise OR 6 ^ binary boolean XOR 6 integer Bitwise XOR 6 (lowest)
_
You can use a numeric expression just about anywhere that a numeric value is expected. In early releases of Motif 1.2,
if you use an expression in an rgb definition, the result is always zero. However, the UIL compiler does place some
restrictions on expressions. An expression must evaluate to a known value when you compile a module, which means
that you cannot use imported numeric values in an expression since the unknown value prevents the compiler from
evaluating the expression.
Like C, UIL lets you mix values of different types in an expression. In this situation, the result of the expression is the
type of the most complex type in the expression. The order of complexity, from lowest to highest, is boolean,
integer, and float. For example, the result of the expression 2 * 2.71828 is the float value 5.43656, and
the result of the expression 15 & true is the integer value 1.
You can explicitly cast any numeric value or numeric expression to a specific type. UIL allows casts to integer,
float, and single_float values, but not to boolean values. The UIL float type is a C double, while the
UIL single_float type is a C float. Here are several examples of casting:
value
one : integer (true);
zero : integer (false);
result : integer (2 * 2.71828);
five_oh : float (5);
g : single_float (9.8);
round : float (integer (2.71828 + 0.5));
When you cast a float value to an integer, the fractional part is always truncated, so the value of result is 5.
A cast to float simply converts an integer or a boolean into a C double. A cast to a single_float is the
only way you can define a C float value, since a floating point literal is always stored as a C double. You must
use a single_float to set a user−defined resource that is a C float. In addition to individual integer values, UIL
supports integer arrays. The compiler does not currently support boolean or floating point arrays, however. The
following code fragment illustrates an array definition:
value
primes : exported integer_table (2, 3, 5, 7, 11, 13);
An integer array consists of the keyword integer_table followed by a list of integer values. Like most other UIL
values, you can export integer arrays from a UIL module or pass them as callback arguments. UIL does not provide a
way to indicate the end of an integer array, so an application must know the length or obtain it somehow. You can
define integer arrays as exported values and fetch them from your application or use them to set the Text and
TextField XmNselectionArray resource. Unfortunately, setting this resource does not work in early releases of
Motif 1.2 because the possible values for the array elements are not defined. Even if you define the values yourself,
based on the definitions in <Xm/Xm.h>, an incompatibility between the two widgets and Mrm prevents an
XmN-selectionArray setting from working properly. This problem has been fixed as of Motif Release 1.2.3.
25 Creating a User Interface With UIL 25.3.3 Numeric Values
675

Get Volume 6A: Motif Programming Manual now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.