Note that there are some explanatory texts on larger screens.

plurals
  1. POFunction pointers - outside library, warning: initialization from incompatible pointer type
    text
    copied!<p>With yours help I finally compiled a code with function pointers. But now I would like to do exact same thing but for functions which are from the "outside" library. typedef, arguments, compilation flags are 100% fine, I got this warning ONLY when I try to call a function from the outside library (when I wrote a function with the same prototype and tried to call it with this code it was just fine). Any ideas?</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include "libs/outlib.h" typedef int (*VFUNCV)(int, double); void call(int which, VFUNCV* fun, int a, double b) { fun[which](a, b); } int main() { VFUNCV fun[2] = {outlibfun1, outlibfun2}; call(0, fun, 3, 4.5); return 0; } </code></pre> <p>Warning:</p> <pre><code>funargs.c: In function ‘main’: funargs.c:14:5: warning: initialization from incompatible pointer type [enabled by default] funargs.c:14:5: warning: (near initialization for ‘fun[0]’) [enabled by default] funargs.c:14:5: warning: initialization from incompatible pointer type [enabled by default] funargs.c:14:5: warning: (near initialization for ‘fun[1]’) [enabled by default] </code></pre> <p>And 14th line:</p> <pre><code>VFUNCV fun[2] = {outlibfun1, outlibfun2}; </code></pre> <p>Declaration of <code>outlibfun</code>: <code>int outlibfun1(int, double);</code></p> <p><strong>ANOTHER NOT-WORKING (WARNING) EXAMPLE:</strong></p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include "libs/outlibz2.h" typedef unsigned char* (*VFUNCV)(const unsigned char *, unsigned long, unsigned char *); void call(int which, VFUNCV* fun, const unsigned char *a, unsigned long b, unsigned char * c) { fun[which](a, b, c); } int main() { VFUNCV fun[2] = {outlibfun1}; call(0, fun, "b", 3, "a"); return 0; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload