title: How to return value from C macro?
body: <p>I was trying to implement the <code>sizeof()</code> operator, and wanted the macro to return the result like the one provided by C lang.</p>
  
  <p>I implemented it using gcc construct '()' like:</p>
  
  <pre><code>#define SIZEOF(type)\   
  ({\ 
   int result;\
   type *p = 0;\
   result = (char*)(p+1)-(char*)p;\
   result;\
  })
  </code></pre>
  
  <p>And used it like this:</p>
  
  <pre><code>x = SIZEOF(double);
  </code></pre>
  
  <p>Is there any way to do it without using gcc construct and returning value from that?</p>
  
  <p>The best i can think of is pass another parameter to macro and store result in that like:</p>
  
  <pre><code>#define SIZEOF(type,result)\
   do{\
     type *p = 0;\
     result = (char*)(p+1)-(char*)p;\
   }while(0)
  </code></pre>
  
  <p>I know that I can replace this macro with inline function which will do the work but was looking for something in macro context. Is there any way to achieve this?</p>