This question already has answers here:
Error: Label used but not defined when using && operator [closed]
(3 answers)
Closed 8 years ago.
Can anyone explain how the following code creates a label?
char memory[] = "hello";
&&memory[0];
error: label 'memory' used but not defined
&&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
Related
This question already has answers here:
Why does C++ allow us to surround the variable name in parentheses when declaring a variable?
(2 answers)
Closed 5 years ago.
I am new to C++, I see following syntax in c++ to initialize variable.
int(i)=1;
Then, I have compiled in G++ compiler and compiler did not give any error or warning.
So, What does mean int(i)=1; in C and C++?
Also, I have tested in C, I thought, the C compiler give an error but it's also working fine.
It's basically a strange way to write
int i = 1;
Nothing to worry about.
Sometimes, parenthesis around the variable name are necessary in defintions (eg. pointer to functions), and there is no reason to prohibit them for other cases, so it's allowed without any deeper reason.
Maythe the author didn't like spaces (such people exist).
This question already has answers here:
scope resolution operator without a scope
(6 answers)
Closed 5 years ago.
I came across a line of code that is quite confusing to me. I tried searching but wasn't sure what to even search for.
The line is as follows:
int i = ++::i;
I am lost to whether this line evaluates to:
int i+= i ;
Any help would be appreciated
In
int i = ++::i;
the :: is there to tell the compiler use the i from the global scope. Without it the compiler is going to use the i you just declared which is undefined behavior. For more on that see Using newly declared variable in initialization (int x = x+1)?
This question already has an answer here:
vector cannot be initialized by {}
(1 answer)
Closed 7 years ago.
I am trying to initialize map in the following way, but I'm not able to do so.
Could you please give me a suggestion?
map<char , int> err_codes = {{'a',1},{'b',0}};
ERROR : initialization with '{...}' is not allowed for object of type
"std::map, std::allocator>>"
It seems your compiler does not support this C++ 2011 feature of list initializations for standard containers. Check the compiler documentation how to switch on the support of C++ 2011 if it is possible.
This question already has answers here:
Why cast an unused function parameter value to void?
(2 answers)
Closed 8 years ago.
I saw following code few times
void func(SomeTypeEGInt varname) {
(void)varname;
}
I wish to know what it means and why people implement such functions.
It tell the compiler that those variables are unused. It is used to prevent the warnings which you will get.
The (void)varname; pattern is typically used to silence compiler warning about unused arguments. So this example is actually an empty function which does nothing.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Address of register variable
I know that getting address of register variable is not allowed in c . But why this code is getting compiled in c++ and not in c.
int main()
{
register int a;
printf("%u\n",&a);
}
The keyword register is only a hint to the compiler. In fact, most compilers today ignore it as they contain advanced code to pick the best register variable candidates anyway.
Whenever you take the address of a variable, it is typically placed on the stack, despite the fact that you have used the register keyword.