# Is this legal syntax?

## Recommended Posts

dave    2187
Hi, I was looking at some source i found online and i saw a code segment where there were 4 '&' ampersands in a row, no white space. Is this legal syntax? ace

##### Share on other sites
Unwise owl    158
Just tried something like this after getting curious:

int a = 1;int* b = &a;int** c = &&a;int*** d = &&&a;int**** e = &&&&a;

Doesn't seem to work...

Nor does:

int a = 1;int* b = &a;int** c = &(&a);int*** d = &(&(&a));int**** e = &(&(&(&a)));

(Returns same error as if I whitespace the ampersands.)

Only int**c = &b; etc. works. Not too surprising as I'd expect an expression such as &a only to generate a value at a temporary address, which in turn you cannot take the address of.

Enigma    1410
Could be.

Enigma

##### Share on other sites
dave    2187
Don't look at the link above, see if you can work it out, :P.

ace

##### Share on other sites
joanusdmentia    1060
To infinity and beyond....
T& T::operator&(){    return *this;}void test(){    T t1;    T t2 = &(&(&(&(&(&t1)))));}

Although it doesn't work without the brackets.

##### Share on other sites
dave    2187
Ok Joanus, show me a code sample that works with what you have written, no whitespace remember. You can't go to infinity with that...

ace

##### Share on other sites
joanusdmentia    1060
Was putting the example in my post as you replied. Checked the link afterwards and was indeed wrong, but the above does compile [smile]

##### Share on other sites
dave    2187
you provide a correct solution but since i didn't ask what i meant, i mean no white spaces or any other character.

ace

##### Share on other sites
_goat    804
Quote:
 Original post by EnigmaCould be.Enigma

Hunh, three question marks. Who would have thought.

##### Share on other sites
Guest Anonymous Poster
Quote:
 Hi, I was looking at some source i found online and i saw a code segment where there were 4 '&' ampersands in a row, no white space. Is this legal syntax? ace

Loved the puzzle but a simpler solution, though not what you expect as an answer (but don't you love it when you find a loophole to a question?):

int main{
char a[10] = "&&&&";
printf("This is legal %s",a);
return 1;
}

##### Share on other sites
dave    2187
You are right, but obviously not the kind of answer we're getting at because it is so blatent.

ace

##### Share on other sites
ZQJ    496
Well, in gcc the following compiles:

int main(){    bool value = true &&&& label;label:    return 0;}

That's actually true && (&&label), where &&label gets the address of the label. It's a gcc extension though, don't know about other compilers.