Why does this syntax compile on gcc?

Started by
0 comments, last by SiCrane 12 years, 1 month ago
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
Advertisement
This is a GCC extension.

This topic is closed to new replies.

Advertisement