Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22113

Are compound statements (blocks) surrounded by parens expressions in ANSI C?

$
0
0

Browsing the Linux kernel sources I found some piece of code where a block of statements surrounded by parenthesis is treated as a expression a la lisp (or ML), that is, an expression which value is the value of the last statement.

For example:

int a = ({    int i;    int t = 1;    for (i = 2; i<5; i++) {        t*=i;    }    t;});

I've been looking at the ANSI C grammar trying to figure out how this piece of code would fit in the parse tree, but I haven't been successful.

So, does anybody know if this behaviour is mandated by the standard or is just a peculiarity of GCC?

Update: I've tried with the flag -pedantic and the compiler now gives me a warning:

warning: ISO C forbids braced-groups within expressions

Viewing all articles
Browse latest Browse all 22113

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>