I've seen using the return value of this macro, but from the definition I can't understnad which is the value that the execution returns.
// packet parsing state machine helpers
#define cursor_advance(_cursor, _len) \
({ void *_tmp = _cursor; _cursor += _len; _tmp; })
Macros don't return anything. Instead invocation of the macros are replaced inline with the body of the macro (with the macro arguments substituted).
So if you have the code
some_variable = cursor_advance(my_cursor, some_length);
then the preprocessor replaces that with
some_variable = ({ void *_tmp = my_cursor; my_cursor += some_length; _tmp; });
This in turn is an extension to the C language by the GCC C compiler called statement expression. It evaluates the statements between the ({ and }), and the result is the last expression. In the case of the example above the result is _tmp.
The whole expression
some_variable = ({ void *_tmp = my_cursor; my_cursor += some_length; _tmp; });
is equivalent to the statements
{
void * _tmp = my_cursor;
my_cursor += some_length;
some_variable = _tmp;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With