title: Is there a safe way to specify the value of an object may be uninitialized because it is never used?
body: <p>Disclaimer: The following is a purely academic question; I keep this code at least 100 m away from any production system. The problem posed here is something that cannot be measured in any “real life” case.</p>
  
  <p>Consider the following code (<a href="https://godbolt.org/g/6cF7Bb" rel="nofollow noreferrer">godbolt link</a>):</p>
  
  <pre class="lang-c prettyprint-override"><code>#include &lt;stdlib.h&gt;
  
  typedef int (*func_t)(int *ptr); // functions must conform to this interface
  
  extern int uses_the_ptr(int *ptr);
  extern int doesnt_use_the_ptr(int *ptr);
  
  int foo() {
      // actual selection is complex, there are multiple functions,
      // but I know `func` will point to a function that doesn't use the argument
      func_t func = doesnt_use_the_ptr;
  
      int *unused_ptr_arg = NULL; // I pay a zeroing (e.g. `xor reg reg`) in every compiler
      int *unused_ptr_arg; // UB, gcc zeroes (thanks for saving me from myself, gcc), clang doesn't
      int *unused_ptr_arg __attribute__((__unused__)); // Neither zeroing, nor UB, this is what I want
  
      return (*func)(unused_ptr_arg);
  }
  </code></pre>
  
  <p>The compiler has no reasonable way to know that <code>unused_ptr_arg</code> is unneeded (and so the zeroing is wasted time), but I do, so I want to inform the compiler that <code>unused_ptr_arg</code> may have any value, such as whatever happens to be in the register that would be used for passing it to <code>func</code>.</p>
  
  <p>Is there a way to do this? I know I’m way outside the standard, so I’ll be fine with compiler-specific extensions (especially for gcc &amp; clang).</p>