Statement Expressions
A statement expression is a compound statement enclosed in parentheses.
A compound statement itself is enclosed in braces { }, so this construct is
enclosed in parentheses-brace pairs ({ }).
The value computed by a statement expression is the value of the last
statement which should be an expression statement. The statement expres-
sion may be used where expressions of its result type may be used. But
they are not allowed in constant expressions.
Statement expressions are useful in the definition of macros as they allow
the declaration of variables local to the macro.
In the following example,
#define min(a,b) ({
short __x=(a),__y=(b),__res;
if (__x > __y)
__res = __y;
else
__res = __x;
__res;
})
int use_min() {
return
}
The
and
foo()
assigned to the variables
expression that
expression because it expands to an expression.
Labels local to a statement expression can be declared with the
keyword. For example,
({
__label__ exit;
VisualDSP++ 3.5 C/C++ Compiler and Library Manual
for ADSP-219x DSPs
min(foo(), thing()) + 2;
statements get called once each because they are
thing()
and
__x
__y
expands to and
min
\
\
\
\
\
\
\
which are local to the statement
can be used freely within a larger
min()
Compiler
__label__
1-139
Need help?
Do you have a question about the VISUALDSP++ 3.5 and is the answer not in the manual?
Questions and answers