'Yacc generated C file sccsid warning supression

I am working on a legacy project that uses yacc - 1.9 20130304. The generated .c files contain the sccsid string (from the skeleton.c):

#ifndef lint
static const char <file_name>sccsid[] = "@(#)yaccpar        1.9 (Berkeley) 02/21/93";
#endif

When compiling with gcc -Wall I get the expected warning:

warning: '<file_name>sccsid' defined but not used [-Wunused-const-variable=]

One way that I can remove the warning is to somehow add __attribute__((unused)) in the generated file but that would be very tedious since the project is huge and contains a lot of parser-generators with a complicated makefile structure.

Therefore I am wondering if there is a simpler way. Can I tell yacc to not generate the sccs id? Or can I instruct gcc to not warn on #ifdef lint? Or maybe some other solution?

Edit: I cannot upgrade to a newer version of byacc (that doesn't insert the sccsid) or modify skeleton.c and recompile yacc because we must ship the software with a specific version of linux and libraries due to software assurance guarantees.

Any suggestions/hints are appreciated!



Solution 1:[1]

Converting comments into an answer.

There are multiple possibilities:

  • You could edit the skeleton.c file? It's a nuisancy fix as you have to redo it on all machines every time Yacc is reinstalled.
  • It looks like Byacc — Berkeley Yacc. You have full rights to change the code — that makes life simpler (and the code won't change often).
  • Alternatively, add -Wno-unused-const-variable to your command-line options, but it might suppress other warnings about other variables that you should pay attention to.
  • Can you afford to compile (the grammar files) with -Dlint? It will eliminate the variable from the compiler's view.

The last (compiling the grammars with -Dlint) is probably the best. Code that is protected by #ifndef lint is rarely crucial to the operation of the code. It was used to hide dubious constructs from the lint program back in the days when lint was used. These days, with proper care in the use of headers and detailed warnings from compilers, lint is rarely used.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jonathan Leffler