Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This works (gcc version 4.6.1):</p> <pre><code>#ifdef __GNUC__ #define SUPPRESS_NOT_USED_WARN __attribute__ ((unused)) #else #define SUPPRESS_NOT_USED_WARN #endif void foo() { } SUPPRESS_NOT_USED_WARN static void bar() { } int main() { return 0; } /* or static void SUPPRESS_NOT_USED_WARN bar() { } etc. */ /* but not, undefined declarations: SUPPRESS_NOT_USED_WARN static void bar(); */ </code></pre> <p>(Edit:)<br /> <a href="http://gcc.gnu.org/onlinedocs/gcc-4.2.4/gcc/Variable-Attributes.html#Variable-Attributes">GCC v4.2.4 doc. 5.32 Specifying Attributes of Variables</a>:</p> <blockquote> <p>unused<br /> &nbsp; &nbsp; &nbsp; &nbsp; This attribute, attached to a variable, means that the variable is meant to be possibly unused. GCC will not produce a warning for this variable. </p> </blockquote> <p>(Edit.2:)<br /> <a href="http://gcc.gnu.org/onlinedocs/gcc-4.2.4/gcc/Function-Attributes.html#Function-Attributes">GCC v4.2.4 doc. 5.25 Declaring Attributes of Functions</a> (a more correct link, functions, sorry about that.)</p> <blockquote> <p>unused<br /> &nbsp; &nbsp; &nbsp; &nbsp; This attribute, attached to a function, means that the function is meant to be possibly unused. GCC will not produce a warning for this function. </p> </blockquote> <hr> <p>When it comes to <code>pragma push</code> and <code>pop</code> etc the documentation say: </p> <p><a href="http://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html">GCC doc. 6.57.10 Diagnostic Pragmas</a>:</p> <blockquote> <p>Modifies the disposition of a diagnostic. Note that not all diagnostics are modifiable; at the moment only warnings (normally controlled by `-W...') can be controlled, and not all of them. Use -fdiagnostics-show-option to determine which diagnostics are controllable and which option controls them.</p> </blockquote> <p>It states; <em>"and not all of them"</em>, <code>-Wunused-function</code> seems to be one of the ones not willing to be suppressed. The option <code>fdiagnostics-show-option</code> seems to be enabled by default. (Gives the flag from which the error/warning enabled.).</p> <p>Using <code>-Wno-unused-function</code> at command line disables it, but then of course for all, not just the ones directly specified in the code.</p> <p>If you say:</p> <blockquote> <p>gcc -Wunused-function -o o mycode.c</p> </blockquote> <p>You'll still get the warning, - so it does not have anything to do with ie <code>-Wall</code> setting the compile process in an special state where it won't work.</p> <hr> <p>As an example this works:</p> <pre><code>int foo(int i) { return i; } int main() { int a; #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wuninitialized" foo(a); #pragma GCC diagnostic pop return 0; } </code></pre>
    singulars
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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