Jump to content

View more

Image of the Day

Boxes as reward for our ranking mode. ヾ(☆▽☆)
#indiedev #gamedev #gameart #screenshotsaturday https://t.co/ALF1InmM7K
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Why does this syntax compile on gcc?

4: Adsense

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   

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

#2 SiCrane   Moderators   

11761
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.