int main()
{
int i = 0;
int *p = &i;
int *q = &&i;
return 0;
}
When compiling this using gcc
on Linux
, I am getting the error
addr.c: In function ‘main’:
addr.c:6:2: error: label ‘i’ used but not defined
Why is the compiler treating int i
as label
and not integer? When do we use && operator
?
EDIT: Okay, I can somewhat understand the answers, but can you explain the below macro definition from "arch/arm/include/asm/processor.h". It doesn't says anything about label
, but the comment says, it can return the "program counter
"
/*
* Default implementation of macro that returns current
* instruction pointer ("program counter").
*/
#define current_text_addr() ({ __label__ _l; _l: &&_l;})
What && operator? There is no unary && operator in C++. GCC has an extension that allows computed goto statements, and that extension uses && to get the address of a label.
Here &&
is the GNU C label address operator.
http://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html
int *q = &&i;
i
must be a label. You have no label i
in your program.
Example of a label:
int main(void)
{
i:
(void) 0;
int i = 0;
int *p = &i;
int *q = &&i;
return 0;
}
I added the (void) 0;
statement as labels in C can only put before statements and not before declarations.
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