Jump to content
  • Advertisement
Sign in to follow this  
Phobon

Why does this syntax compile on gcc?

This topic is 2481 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 all you C gurus! smile.png

I've recently found a strange piece of C syntax in our codebase which I can't quite explain... (simplified version below)


#define ARR(a, i) (*({assert(i>0); &arr;}))


Note the semicolons and {} in the definition!
Is this code standard C ? What is this behaviour called?
It definitely compiles and runs as expected with gcc.

I'd only have known hot to write this using the comma-operator:


#define ARR(a, i) (*(assert(i>0), &arr))


Just wondering, how much of the C standard I don't know... blink.png

Phobon

Share this post


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

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!