Jump to content
  • Advertisement
Sign in to follow this  
dave

Is this legal syntax?

This topic is 4588 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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 this post


Link to post
Share on other sites
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 this post


Link to post
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!