Conditional Expressions With Omitted Middle Operands - Intel i960 User Manual

Processor compiler
Hide thumbs Also See for i960:
Table of Contents

Advertisement

7
7-44
i960 Processor Compiler User's Guide
Conditional Expressions with Omitted Middle
Operands
The middle operand in a conditional expression may be omitted. Then if
the first operand is nonzero, its value is the value of the conditional
expression.
Therefore, the expression:
x ? : y
has the value of
if that is nonzero; otherwise, the value of
x
This example is perfectly equivalent to:
x ? x : y
In this simple case, the ability to omit the middle operand is not especially
useful. When it becomes useful is when the first operand does, or may (if
it is a macro argument), contain a side effect. Then repeating the operand
in the middle would perform the side effect twice. Omitting the middle
operand uses the value already computed without the undesirable effects
of recomputing it.
Arrays of Length Zero
Zero-length arrays are allowed. They are very useful as the last element
of a structure that is really a header for a variable-length object:
struct line {
int length;
char contents[0];
};
{
struct line *thisline
= (struct line *) malloc \
(sizeof (struct line) + this_length);
thisline->length = this_length;
}
.
y

Advertisement

Table of Contents
loading

Table of Contents