I used alk answer but I'm giving more details for those facing the same problem.
First part:
alk suggested to define a macro named unused
. Since it's a large project with several build units and Makefiles, I decided to define the macro using gcc:
gcc -Dunused= ...
Then, I've cleaned-up the project and rebuilt:
make clean && make
That went very badly because of variables called unused_something in the code. So I had to rename these variables in order to continue.
Since I'm using the -Wall
option, I'm now getting a lot of warnings that all look like:
char/serial.c: In function ‘serial_write’:
char/serial.c:151:69: warning: unused parameter ‘odf’ [-Wunused-parameter]
static size_t serial_write(tty_struct_t *tty, open_file_descriptor* odf __attribute__((unused)), const unsigned char* buf, size_t count)
^
So I reran with:
make clean && make > out 2>&1
And now, I grep the result:
grep Wunused-parameter out
I'm getting all the warnings with the name of the file and the line number.
Second part:
Since I use git, I can directly do:
git grep -n "((unused))"
With that, I have all the lines containing the attribute unused. However, if a line contains two or more unused attribute, I'll get it only once.
Last part:
I check which lines are not on both outputs, manually :/.