Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7691433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:37:17+00:00 2026-05-31T20:37:17+00:00

I have a C program with a couple of static functions that are not

  • 0

I have a C program with a couple of static functions that are not (yet) used. I want to disable warnings for those specific functions. I do not want to disable all -Wunused-function warnings. I am using GCC 4.6. Specifically:

gcc --version

gcc (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

I am following the advice in the documentation (to use push and pop), but I have not been able to get it to work.

I have created some simplified source code to investigate the problem. I am compiling them with gcc -Wall -o pragma pragma.c (where pragma.c). My first version of pragma.c looks like this:

void foo(int i) { }
static void bar() { }
int main() { return 0; }

As expected, I get this when I compile it:

pragma.c:3:13: warning: ‘bar’ defined but not used [-Wunused-function]

Also as expected, I am able to disable the warning like this (then the compile succeeds silently):

#pragma GCC diagnostic ignored "-Wunused-function"
void foo(int i) { }
static void bar() { }
int main() { return 0; }

But then, I tried this:

void foo(int i) { }
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
static void bar() { }
#pragma GCC diagnostic pop
int main() { return 0; }

When I compiled that, I got the original warning:

pragma.c:4:13: warning: ‘bar’ defined but not used [-Wunused-function]

Removing the pop gets rid of the warning:

void foo(int i) { }
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
static void bar() { }
int main() { return 0; }

But I need a way to disable the warning just for a specific section of code. I have not been able to do that.

It is hard for me to imagine how this could be intended behavior…but many others have used this version of GCC and it seems unlikely that, if this were a bug, it would make it into the release version.

Still, I have trouble seeing how this behavior is consistent with the documentation, which says that "pragmas occurring after a line do not affect diagnostics caused by that line."

What am I doing wrong? Is there more information about the problem, such as a bug report and/or information about possible workarounds?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T20:37:19+00:00Added an answer on May 31, 2026 at 8:37 pm

    This works (GCC version 4.6.1):

    #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();
    */
    

    GCC v4.2.4 doc. 5.32 Specifying Attributes of Variables:

    unused
            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.

    GCC v4.2.4 doc. 5.25 Declaring Attributes of Functions (a more correct link, functions, sorry about that.)

    unused
            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.


    When it comes to pragma push, pop, etc,, the documentation say:

    GCC doc. 6.57.10 Diagnostic Pragmas:

    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.

    It states; "and not all of them", -Wunused-function seems to be one of the ones not willing to be suppressed. The option fdiagnostics-show-option seems to be enabled by default. (Gives the flag from which the error/warning enabled.).

    Using -Wno-unused-function at command line disables it, but then of course for all, not just the ones directly specified in the code.

    If you say:

    gcc -Wunused-function -o o mycode.c

    You’ll still get the warning, – so it does not have anything to do with, e.g., the -Wall setting for the compile process in an special state where it won’t work.


    As an example, this works:

    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;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have program that runs fast enough. I want to see the number of
I have a program I made in C++ that does not use classes, just
We have a program that take specific XML files and imports them, then changes
We have a program that needs to have its contents refreshed every couple of
I have program that has a variable that should never change. However, somehow, it
I have program, that must interact with a console program before my program can
I have a program that spits out both standard error and standard out, and
I have a program that creates a Windows user account using the NetUserAdd() API
I have a program that uses the mt19937 random number generator from boost::random. I
I have a program that spits out an Excel workbook in Excel 2003 XML

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.