• Advertisement
Sign in to follow this  

Why does this syntax compile on gcc?

This topic is 2156 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