4

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
doron
  • 27,972
  • 12
  • 65
  • 103
  • Possible duplicate of http://stackoverflow.com/questions/4549151/c-double-address-operator ? (If not, you may want to look into this if you haven't already) – Chris Sprague Dec 12 '14 at 14:49
  • @ChrisSprague: No, that's a different use of `&&` in a type specifier, to denote an _rvalue_ reference. Here, it's used as an operator in an expression. – Mike Seymour Dec 12 '14 at 14:50
  • @MikeSeymour Yikes - that makes 3 completely different interpretations of `&&` in C++. Scary! Thanks for clarification. – Chris Sprague Dec 12 '14 at 14:55
  • @ChrisSprague: Only two in standard C++, since this is an extension. But there are three meanings of `&`. And several meanings of `static`. – Mike Seymour Dec 12 '14 at 15:08

1 Answers1

9

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.

Mike Seymour
  • 249,747
  • 28
  • 448
  • 644