Skip to main content
GameDev.net gamedev.net
🔒 Locked

Why does this syntax compile on gcc?

Started by Phobon Feb 28, 2012 at 2:47 PM 0 replies 1.5k views
Original Post
Phobon
Phobon
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.