Jump to content

  • Log In with Google      Sign In   
  • Create Account

Why does this syntax compile on gcc?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Phobon   Members   -  Reputation: 247

Like
0Likes
Like

Posted 28 February 2012 - 08:47 AM

Hi all you C gurus! Posted Image

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[i];}))

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[i]))

Just wondering, how much of the C standard I don't know... Posted Image

Phobon

Sponsor:

#2 SiCrane   Moderators   -  Reputation: 9597

Like
1Likes
Like

Posted 28 February 2012 - 08:58 AM

This is a GCC extension.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS