Next: , Previous: , Up: Crash Introduction   [Index]


3.1.3 Evaluating An Expression

Translating the expression into a single value can be done as:

status = x1f4_link_expression(expression, &output);

See x1f4_link_expression.

See Functions.

See Prefix Unary Operators.

See Infix Binary Operators.

The second x1f4_link_expression parameter indicates a memory location to which the result of the expression evaluation should be stored. Enough space to store the result, of which the type can be determined via x1f4_type_expression, should be available at the specified location.

Since this examples uses only the intrinsic types the minimum memory requirements for result storage are no greater than the union of all possible output types. The:

union state_type {
    X1f4_E4_C_BILL bill;
    X1f4_E4_C_MODE mode;
    X1f4_E4_C_REAL real;
    X1f4_E4_C_TEXT text;
};

See C Types.

type is large enough to hold any computed value. In the above x1f4_link_expression function call example, output was assumed declared as:

union state_type output;

The result will be stored at the address indicated, and thus accessing the result via the union state_type members will produce undefined results.

In plain C, to access the expression evaluation results, one may cast the result storage address to the corresponding pointer type and read the result from the first location. Like in:

if (type == X1f4_E4_BILL) {
    *(X1f4_E4_C_BILL *) &output
} else {
    if (type == X1f4_E4_MODE) {
	*(X1f4_E4_C_MODE *) &output
    } else {
	if (type == X1f4_E4_REAL) {
	    *(X1f4_E4_C_REAL *) &output
	} else {
	    if (type == X1f4_E4_TEXT) {
	        *(X1f4_E4_C_TEXT *) &output
	    } else {
	        no result, the expression evaluated void
	    }
	}
    }
}