Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I quiet the C compiler about a function pointer takes any number of arguments?
    primarykey
    data
    text
    <p>I have a function pointer inside a <code>struct</code> that gets dynamically set at runtime to the address of another function in various places in my code. It is defined in my header file like this:</p> <pre><code> void *(*run)(); </code></pre> <p>During compile time, I get the following warning about this:</p> <pre><code> warning: function declaration isn't a prototype </code></pre> <p>This warning is benign, because the pointer is used in many places in my code to call the function it points to, and everything works just fine. However, I would <em>really</em> like to silence the warning.</p> <p>If I change it to this:</p> <pre><code> void *(*run)(void); </code></pre> <p>I get compile errors whever I use it, because the various functions that make use of the pointer have different numbers of arguments, and saying <code>void</code> inside the parenthesies tells the compiler it accepts no arguments.</p> <p>I can't use a <code>va_list</code> or anything fancy like that, as this is simply a pointer to another function, and I use a single pointer for them all because it keeps the code clean and simple.</p> <p>I can silence the warning with adding this to my compiler flags:</p> <pre><code> -Wno-strict-prototypes </code></pre> <p>But I'd rather not have to disable compiler warnings with flags if I can avoid it.</p> <p>So my question is: <strong>How do I notate this function pointer in the code in such a way that the compiler is satisfied with the fact that it accepts any number of any kind of arguments?</strong></p> <p>The code works perfectly. I just want the warning to go away.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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