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:
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: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.)
I’m currently using names based on file name:
jlss_id_filename_c[]etc.The AT&T SVR4 C compiler and support software supported a
#identdirective:The compiler included the strings in a ‘comments’ section in the object file, and a tool (
mcs) to manipulate the comments section (options-dto delete it and-cto compress it, IIRC). This section was part of the binary, but not loaded into memory at runtime.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:
However, I normally remove the declaration these days, and don’t get compiler warnings.
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.
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:
Then, when I want the headers to define the values, I have
#define MAIN_PROGRAMat the top of the corresponding source file. For example, from runningwhat errnoon a program of that name, I get the output:Old-style
This is a complete (and very useful) program illustrating the old-style of doing business.
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:
When I run
what al, I get no identification output.