title: Is it legal to cast a function to a pointer to a function of various kinds per C standard?
body: <p>I analyzed some source code written in C and found the following code snippet:</p>
  <pre><code>#include &lt;stdio.h&gt;
  
  struct base_args_t {
  int a0;
  };
  
  struct int_args_t {
  struct base_args_t base;
  int a1;
  };
  
  struct uint_args_t {
  struct base_args_t base;
  unsigned int a1;
  };
  
  void print_int(struct int_args_t *a)
  {
      // print int
      printf(&quot;%i\n&quot;, a-&gt;a1);
      return;
  }
  
  void print_uint(struct uint_args_t *a)
  {
      // print unsigned int
      printf(&quot;%u\n&quot;, a-&gt;a1);
      return;
  }
  
  int main()
  {
      struct uint_args_t uint_args = {.a1 = 7};
      typedef void (*f_print_type)(struct int_args_t *);
      void (*print)(struct int_args_t *a) = (f_print_type)print_uint;
  
      print((void *)&amp;uint_args);
  
      return 0;
  }
  </code></pre>
  <p>I am wondering if it is permissible to cast a function to a pointer to a function of various kinds, as is done in the example:</p>
  <pre><code>void (*print)(struct int_args_t *a) = (f_print_type)print_uint;
  </code></pre>
  <p>P.S. Moreover, I've tested this example with enabled CFI sanitizer and it says:</p>
  <blockquote>
  <p>runtime error: control flow integrity check for type 'void (struct
  int_args_t *)' failed during indirect function call</p>
  </blockquote>
  <p>but it’s hard to say whether it is 100% correct.</p>