2

Can anyone explain how the following code creates a label?

char memory[] = "hello";
&&memory[0];

error: label 'memory' used but not defined
Deduplicator
  • 44,692
  • 7
  • 66
  • 118

1 Answers1

6
&&memory[0];

That's not valid C++, thus a conforming extension can assign any semantics one could want to it.

It so happens, that &&label is the GNU folks' way of taking the address of a label for computed goto's, a GNU extension.

That's it.

Reference: https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
  • The whole meaning of the expression to the GNU compiler is that first the (undefined) label `memory` is resolved to an address [(of type `void *`)](http://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html) and then this pointer is subscripted via the `[0]` part, which happens to be an invalid operation too. (You might want to include the link in your answer.) – 5gon12eder Sep 11 '14 at 23:50
  • Well, certainly they also have that irritating extension of allowing pointer-arithmetic on `void*` (I think that's not a conforming extension for c++). – Deduplicator Sep 11 '14 at 23:53
  • Oops, `[]` actually seems to bind more tightly than `&&` and `(&&label)[0]` crashes GCC 4.9.0. – 5gon12eder Sep 12 '14 at 00:02