0

test.c

#include <stdio.h>
int main(void)
{
    int a = 13; 
    const int **pp = &&a;
    return 0;
}

Look at the above code.

I know it is not right.

However, my question is about the error message that I don't understand.

I thought the error message would contain things like "lvalue unary operand required" or something.

After cc -std=c11 test.c, I got this:

test.c: In function ‘main’:
test.c:7:2: error: label ‘a’ used but not defined
  const int **pp = &&a;

I think a should be called a variable or identifier which is defined already by using int a = 13;

What is label in the error message for C programming language after error compilation?

  • What does address of the address of 'a' even mean in this context? What compiler is giving you this error message? – jwdonahue Oct 08 '18 at 02:20
  • I get `C2059 syntax error: '&&' StackOverFlow d:\repo\wip\ctest\stackoverflow\stackoverflow\source.c 11`. – jwdonahue Oct 08 '18 at 02:22
  • 1
    I suspect the compiler you are using has some extension where the address of a label can be taken with `&&`. In unextended C, `&&` is a single operator; it is not `& &`. You can only take the address of an object; you cannot take the address of an address. – Eric Postpischil Oct 08 '18 at 02:22
  • 1
    Possible duplicate of [What does && mean in void \*p = &&abc;](https://stackoverflow.com/questions/6106493/what-does-mean-in-void-p-abc) – Joseph Sible-Reinstate Monica Oct 08 '18 at 02:23

1 Answers1

3

You've stumbled across a non-standard GCC feature called Labels As Values.

Change your code to the following and see what happens.

#include <stdio.h>
int main(void) 
{
    int a = 13; 
    void *pp = &&a;
    goto *pp;
    return 0;
a:
    printf("ooooops\n");
    return 0;
}

It's basically a way to use goto labels as values, in the sense that you can assign a label to void * pointer, and then use that pointer in a goto statement.

This is not standard C, to make sure you don't use any non-standard features set -std to -std=c99 or what ever standard you'd like to use.

nullp0tr
  • 485
  • 3
  • 11