Take the 2-minute tour ×

In a generated piece of c code I found something like this (edited):

#include <stdio.h>

int main() {

  (void) (
      int i = 1;
      int y = 2;

      printf("%d %d\n", i,y);

  return 0;

I believe I have never seen the construct (void) ( { CODE } ) before, nor am I able to figure out what the purpose might be.

So, what does this construct do?

share|improve this question
add comment

2 Answers

up vote 12 down vote accepted

({ }) is a gcc extension called a statement expression.


A statement expression yields a value and the (void) cast is probably here to remove the compiler warning or to make explicit that the value of the statement expression is not used.

Now (void) ({ }) is the same as a simple compound statement {} and there is no point of using it.

share|improve this answer
There is one purpose: all the variables are in the lexical scope. –  texasbruce Nov 3 '12 at 16:37
@texasbruce which is what does a compound statement, there is no need to use a non-portable construct for that. –  ouah Nov 3 '12 at 16:51
add comment

One application of ({ }) is the ability to replace expressions with code blocks. In this way very complex macros can be embedded in to expressions.

#define myfunc() {   }    // can be a typical way to automatize coding. e.g.

myfunc(x,z,y);  // would work to eg. unroll a loop
int a = myfunc()*123;  // but this wouldn't work


#define myfunc(a,b,c) ({printf(a#b#c);})
int a= myfunc(a,b,c) * 3; // would be legal
share|improve this answer
add comment

Your Answer


