While reading one of LLVM static analyzer documents, I stumbled upon a strange operator.
^{ int y = x; }();
I know I can define a nested block inside a function like { ... }, but can we even call it? Also, I've never seen any usage placing ^ in front of a curly bracket block. I thought this is kind of a language extension supported by GCC and googled this with keywords like anonymous function or lambda but was of no avail. Is there anyone who has any idea about this?
From Clang 9 Documentation Language Specification for Blocks it's a Block Literal Expression. It has the form of (from wiki):
^return_type ( parameters ) { function_body }
But:
If the return type is omitted and the argument list is ( void ), the ( void ) argument list may also be omitted.
The following:
^{ int y = x; }();
is equal to:
( ^void (void) { int y = x; } )();
is equal to:
void (^f)(void) = ^void (void) { int y = x; };
f();
It declares a block literal that does int y = x
and immediately after declaring executes is.
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