title: Why this macro is defined as ({ 1; })?
body: <p>In multiple ARM back-end of Linux, I'm seeing in files <code>clkdev.h</code> this macro definition:</p>
  
  <pre><code>#define __clk_get(clk) ({ 1; })
  </code></pre>
  
  <p>See for example  <a href="http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=arch/arm/mach-versatile/include/mach/clkdev.h;h=e58d0771b64e090151a0d98a69fbd4221a1597d3;hb=HEAD#l13" rel="nofollow noreferrer">./arch/arm/mach-versatile/include/mach/clkdev.h</a></p>
  
  <p>This macro is using GCC extension <a href="http://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html" rel="nofollow noreferrer"> Statements and Declarations in Expressions</a></p>
  
  <p>Later this macro is used in file <a href="http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=drivers/clk/clkdev.c;h=442a31363873d35f319e0d5ee5b6b250084c02fc;hb=HEAD#l145" rel="nofollow noreferrer">./drivers/clk/clkdev.c</a>, in function <code>clk_get_sys()</code></p>
  
  <pre><code> if (cl &amp;&amp; !__clk_get(cl-&gt;clk))
           cl = NULL;
  </code></pre>
  
  <p>I'm wondering why not using here a simple macro:</p>
  
  <pre><code>#define __clk_get(clk) (1)
  </code></pre>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I've found some other usage of this construct throughout the kernel sources using the following grep pattern:</p>
  
  <pre><code>grep -R '({[[:space:]]*[a-zA-Z0-9_()+=/!&amp;*&gt;., ?:-]\+[[:space:]]*;[[:space:]]*})' .
  </code></pre>
  
  <p>Here's some of the matches:</p>
  
  <pre><code>./kernel/trace/trace_selftest.c:# define trace_selftest_startup_dynamic_tracing(trace, tr, func) ({ 0; })
  ./kernel/profile.c:#define create_hash_tables()         ({ 0; })
  ./include/asm-generic/bug.h: * Use of ({0;}) because WARN_ON_SMP(x) may be used either as
  ./include/asm-generic/bug.h:# define WARN_ON_SMP(x)         ({0;})
  ./include/linux/key.h:#define key_get(k)            ({ NULL; })
  ./include/linux/key.h:#define key_get(k)            ({ NULL; })
  ./include/linux/audit.h:#define audit_alloc(t) ({ 0; })
  ./include/linux/audit.h:#define audit_bprm(p) ({ 0; })
  ./include/linux/audit.h:#define audit_sockaddr(len, addr) ({ 0; })
  ./include/linux/audit.h:#define audit_log_bprm_fcaps(b, ncr, ocr) ({ 0; })
  ./include/linux/audit.h:#define audit_log_start(c,g,t) ({ NULL; })
  ./include/linux/atalk.h:#define atalk_proc_init()   ({ 0; })
  ./include/linux/ftrace.h:#define register_ftrace_function(ops) ({ 0; })
  ./include/linux/ftrace.h:#define unregister_ftrace_function(ops) ({ 0; })
  ./include/linux/ftrace.h:#define ftrace_regex_open(ops, flag, inod, file) ({ -ENODEV; })
  ./include/linux/ftrace.h:#define ftrace_set_filter(ops, buf, len, reset) ({ -ENODEV; })
  ./include/linux/ftrace.h:#define ftrace_set_notrace(ops, buf, len, reset) ({ -ENODEV; })
  ./include/linux/cpu.h:#define unregister_hotcpu_notifier(nb)    ({ (void)(nb); })
  ./include/linux/proc_fs.h:#define proc_net_fops_create(net, name, mode, fops)  ({ (void)(mode), NULL; })
  ./arch/powerpc/include/asm/pgtable-ppc64.h:#define pgd_set(pgdp, pudp)  ({pgd_val(*(pgdp)) = (unsigned long)(pudp);})
  ./arch/sh/math-emu/math.c:#define WRITE(d,a)    ({if(put_user(d, (typeof (d)*)a)) return -EFAULT;})
  ./arch/sh/math-emu/math.c:#define READ(d,a) ({if(get_user(d, (typeof (d)*)a)) return -EFAULT;})
  [...]
  </code></pre>
  
  <p>Note: the construct <code>({if(put_user(d, (typeof (d)*)a)) return -EFAULT;})</code> seems to be a good usage of the compound statement. But this can also be replaced by more typical <code>do { if(put_user(d, (typeof (d)*)a)) return -EFAULT; } while(0)</code> </p>
  
  <p>One match returned by <code>grep</code> is interesting: in <a href="http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=include/asm-generic/bug.h;h=7d10f962aa137776389daf226b42b8be9702e1bd;hb=HEAD#l196" rel="nofollow noreferrer">./include/asm-generic/bug.h</a> there's a comment of usage of <code>({ 0; })</code>. This is quite the same <a href="https://stackoverflow.com/a/13947505/611560">answer</a> of  <a href="https://stackoverflow.com/users/187690/andreyt">AndreyT</a>.</p>
  
  <p>Indeed, one cannot use <code>((void)0)</code>, since it won't be usable as a r-value.
  <code>({ 0; })</code> is working in each case.</p>
  
  <p>So if you have a macro that can used like a function returning a value that can be used or not, the compound statement seems to be your only option.</p>
  
  <p><strong>But <code>__clkget()</code> is never used as anything else as a r-value</strong></p>
  
  <h2>Some links</h2>
  
  <ul>
  <li><a href="http://www.toofishes.net/blog/gcc-compound-statement-expressions/" rel="nofollow noreferrer">http://www.toofishes.net/blog/gcc-compound-statement-expressions/</a></li>
  <li><a href="https://stackoverflow.com/questions/10166275/abstruse-define-macro-encountered-in-linux-kernel-source">Abstruse #define macro encountered in Linux kernel source</a></li>
  <li><a href="https://stackoverflow.com/questions/7604971/macro-does-define-ab-c-means-ab-returns-c">macro: does #define a(b) ({... c;}) means a(b) returns c?</a></li>
  <li><a href="https://stackoverflow.com/questions/8142280/why-do-we-need-parentheses-around-block-macro">Why do we need parentheses around block macro?</a></li>
  <li><a href="https://stackoverflow.com/questions/1238016/are-compund-statements-blocks-surrounded-by-parens-expressions-in-ansi-c">Are compound statements (blocks) surrounded by parens expressions in ANSI C?</a></li>
  </ul>