In comments, you clarify that
My intent is to truly (or as closely as possible) emulate Statement
Expressions, to be used in every way that they can be used, with every
property they have.
Therefore, let's look at how statement expressions are formed and what they do:
A compound statement enclosed in parentheses may appear as an
expression in GNU C. This allows you to use loops, switches, and local
variables within an expression.
[...]
The last thing in the compound statement should be an expression
followed by a semicolon; the value of this subexpression serves as the
value of the entire construct.
(GCC Documentation)
There are two key parts to that:
The construct is built around a compound statement, and therefore can have within anything that a compound statement can have.
The construct evaluates to a value.
Moreover, you explicitly say
Specifically, the result of the last statement of the compound
expression should carry both its type AND value out, not have those
passed in as a macro parameter.
You have painted yourself into a corner here. C statements are not expressions, which exactly means that they do not evaluate to values. It is why GCC statement expressions are an extension. Values have no linkage, and to the extent that they can be considered to have scope, it is limited to the expressions in which they appear and to the objects that store them. The only way to transfer a value out of a statement is to assign it to an object of appropriate type (and you expressly want to avoid doing that) or to return
it (which requires it to be in a function).
There are other characteristics of statement expressions that may have attracted your interest in the first place. In particular, inasmuch as you brought up lambdas, I suspect you're interested in the fact that statement expressions live inside the context of the surrounding code, so that, among other things, they can use the identifiers that are in scope there. If that's what you're after then you probably need to just write ordinary blocks of code, and provide variables in which to report out the result.
HOWEVER, there is another alternative that could give you a little of what you're after. You can compute several expressions in turn, each able to make use of the side effects of the previous ones, by using the comma operator. For example,
int first = 1, second = 2, temp, new_first;
new_first = (temp = second, second = first, first = temp);
The result is that the values of first
and second
are swapped, with the resulting new value of first
being assigned to new_first
. Of course, this does not afford loops, if
statements, etc, and it especially does not provide for declaring local variables, such as temp
. As I said a little of what statement expressions can do.