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 6880377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:57:58+00:00 2026-05-27T04:57:58+00:00

We need to define a const static char pointer in each and every header

  • 0

We need to define a const static char pointer in each and every header (.h) and source (.cpp) file to comply with company coding standards.

static const char * one_time_param = "ABCDEFG";

When compiled, the compiler is generating lot of “defined but not used” warnings. Does someone have a solution to this issue, please?

-Wno-unused-parameter

Using the above compiler flag, we can suppress these warnings. But, this also suppresses some other unused parameters which might need attention. We tried these solutions which only work for function parameters.

Q_UNUSED

in Qt, and

#define UNUSED(x) ((void)(x))

Previous question of similar kind:

How can I hide "defined but not used" warnings in GCC?

  • 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-27T04:57:59+00:00Added an answer on May 27, 2026 at 4:57 am

    First – the company coding standards are arguably wasting space. If you’re going to do that, then use an array instead of a char * so you store just the data and not a pointer and the data:

    static const char one_time_param[] = "ABCDEFG";
    

    Next, presumably this is for file identification – that, at least, is what I use it for. There are several things to be aware of, learned from experience over a number of years. (I still like to embed version numbers in the source files – I haven’t whole-heartedly moved to DVCS because of this.)

    1. To avoid the warnings, you have to make the symbols visible outside the file.
    2. That, in turn, means you have to make the variable names unique.
    3. I’m currently using names based on file name: jlss_id_filename_c[] etc.

      #ifndef lint
      /* Prevent over-aggressive optimizers from eliminating ID string */
      const char jlss_id_errno_c[] = "@(#)$Id: errno.c,v 3.3 2011/09/07 22:33:45 jleffler Exp $";
      #endif /* lint */
      
    4. The AT&T SVR4 C compiler and support software supported a #ident directive:

      #ident "@(#)$Id: errno.c,v 3.3 2011/09/07 22:33:45 jleffler Exp $"
      

      The compiler included the strings in a ‘comments’ section in the object file, and a tool (mcs) to manipulate the comments section (options -d to delete it and -c to compress it, IIRC). This section was part of the binary, but not loaded into memory at runtime.

    5. At one point in GCC’s evolution, in conjunction with the command line options I was using, I got warnings unless I declared as well as defined the variable, so my ‘template’ for new source file generates:

      #ifndef lint
      /* Prevent over-aggressive optimizers from eliminating ID string */
      extern const char jlss_id_filename_c[];
      const char jlss_id_filename_c[] = "@(#)$Id$";
      #endif /* lint */
      

      However, I normally remove the declaration these days, and don’t get compiler warnings.

    6. As an alternative to using the file name as the basis of variable name, you could generate a UUID or GUID name in hex and use that as the variable name, with a prefix to ensure the first character is alphabetic.

    7. In headers, you don’t want that material defined in every source file that includes the header because (a) it becomes a noticable (but not necessarily significant) overhead on program size, and (b) you can’t multiply define global variables (you can multiply declare them; that’s not a problem). So, my headers have a stanza like:

      #ifdef MAIN_PROGRAM
      #ifndef lint
      /* Prevent over-aggressive optimizers from eliminating ID string */
      const char jlss_id_stderr_h[] = "@(#)$Id: stderr.h,v 10.3 2011/11/28 04:49:24 jleffler Exp $";
      #endif /* lint */
      #endif
      

      Then, when I want the headers to define the values, I have #define MAIN_PROGRAM at the top of the corresponding source file. For example, from running what errno on a program of that name, I get the output:

      errno:
      $Id: errno.c,v 3.3 2011/09/07 22:33:45 jleffler Exp $
      $Id: range.h,v 1.8 2008/02/11 07:39:36 jleffler Exp $
      $Id: stderr.h,v 10.3 2011/11/28 04:49:24 jleffler Exp $
      $Id: errhelp.c,v 8.5 2009/03/02 19:13:51 jleffler Exp $
      $Id: range2.c,v 1.8 2008/02/11 08:44:50 jleffler Exp $
      $Id: stderr.c,v 10.7 2011/11/28 04:49:24 jleffler Exp $
      stderr.c configured with USE_STDERR_FILEDESC
      stderr.c configured with USE_STDERR_SYSLOG
      

    Old-style

    This is a complete (and very useful) program illustrating the old-style of doing business.

    /*
    @(#)File:            $RCSfile: al.c,v $
    @(#)Version:         $Revision: 1.4 $
    @(#)Last changed:    $Date: 1996/08/13 11:14:15 $
    @(#)Purpose:         List arguments one per line
    @(#)Author:          J Leffler
    @(#)Copyright:       (C) JLSS 1992,1996
    @(#)Product:         :PRODUCT:
    */
    
    /*TABSTOP=4*/
    
    #include <stdio.h>
    #include <stdlib.h>
    
    #ifndef lint
    static const char sccs[] = "@(#)$Id: al.c,v 1.4 1996/08/13 11:14:15 johnl Exp $";
    #endif
    
    int main(int argc, char **argv)  
    { 
        while (*++argv) 
            puts(*argv);
        return(EXIT_SUCCESS); 
    }
    

    NB: When that is compiled, the version string is not included in the binary (or the object file). This does not currently give me any warning when compiled with GCC 4.6.1 compiled on MacOS X 10.7.2:

    gcc -m64 -g -O -std=c99 -pedantic -Wall -Wshadow -Wpointer-arith -Wcast-qual \
        -Wstrict-prototypes -Wmissing-prototypes -o al al.c
    

    When I run what al, I get no identification output.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a assets file that embeds things, [Embed(source='assets.swf', symbol='block')] public static const SYM_BLOCK:Class;
I need to define a Wix file component that may not exist in certain
I need to define multiple modules in the same file. I would like to
I'm writing a config file and I need to define if the process expects
If I have the following in a header file: Foo.h Foo { public: static
I need to define a calculated member in MDX (this is SAS OLAP, but
I need to define new UI Elements as well as data binding in code
I need to define the constant in the module that use the method from
I need to define an appender for log4net in a way that I get
I need to define some constant strings that will be used only by one

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.