0

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!

  • How about using that variable? Surely the code has some sort of "who am I and what version am I" feature. Just modify that code to emit it somehow. Another way would be to emit it to the null device. – Jeff Holt Apr 29 '22 at 21:37
  • 1
    Can you not edit the `skeleton.c` file? It's a nuisancy fix as you have to redo it on all machines every time the 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. – Jonathan Leffler Apr 29 '22 at 21:46
  • @JonathanLeffler `-Dlint` does work indeed, thanks! I tested it on one .y file and it doesn't seem to impact the compile that much. Unfortunately `skeleton.c` is part of yacc and I cannot recompile it or use a newer version of byacc because this piece of software comes with software assurance guarantees. – Emanuel Hristea Apr 29 '22 at 21:57

1 Answers1

0

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.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278