I am looking at the code below which comes from JavascriptCore and I don't know what the meaning of the && is in the context below. An address of an address does not really make sense.
So can someone explain what the && means in the context below.
(the bitwise_cast uses a union to avoid strict aliasing problems that come with a reinterpret_cast)
The code below compiles on clang (and presumably gcc) but does not compile on our own proprietary C++ compiler.
The full source can be found here.
#if ENABLE(COMPUTED_GOTO_OPCODES)
Opcode* opcodeMap = LLInt::opcodeMap();
#define OPCODE_ENTRY(__opcode, length) \
opcodeMap[__opcode] = bitwise_cast<void*>(&&__opcode); //<---- The double &&
FOR_EACH_OPCODE_ID(OPCODE_ENTRY)
#undef OPCODE_ENTRY
#define LLINT_OPCODE_ENTRY(__opcode, length) \
opcodeMap[__opcode] = bitwise_cast<void*>(&&__opcode);
FOR_EACH_LLINT_NATIVE_HELPER(LLINT_OPCODE_ENTRY)
#undef LLINT_OPCODE_ENTRY
#endif
That's a GCC extension: computed goto.
Given a goto
label
label:
in standard C++, you can only jump to it directly:
goto label;
but GCC allows you to store its address with a non-standard use of &&
as a unary operator (analogous to &
for taking the address of an object, function, or member):
void * ptr = &&label;
and use that pointer later:
goto *ptr;
It looks like you can disable this through the preprocessor, for your compiler which doesn't have this extension. It will use some scheme based on a switch
statement instead of computed jump label.
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