Side effects within a typeof() expression

Viewed 417

In GNUC C, you can use typeof(expression), and it is legal to use an expression with side effects inside. So for example you can have this C code:

int x = 0;
typeof(x++) y;

In this case, the side effect is ignored and x is still zero afterwards (this makes sense as types are a compile-time-only thing).

However, the GCC documentation says:

The operand of typeof is evaluated for its side effects if and only if it is an expression of variably modified type or the name of such a type.

What does this sentence mean? Is it really possible to write typeof with a side effect and have the side effect actually be executed at runtime? For me, this sentence seems to indicate this.

1 Answers
Related