Define statements are used to make code mode readeable, but often defines are changed, new ones are created, and after months of coding, there could be a lot of them unused.
Three are a huge number of code analisys tools that will do the job, but if you don’t want to buy or install them, you can use the bash to find which defines are unused.
Imagine you have your code into the directory ~/code, cd into it
cd ~/code
create a list containing all the defines mnemonics
grep -r -sw '#define' | awk '{print $2}' > ../mnemonics.txt
search into your source code how many times is used each entry in the ../list.txt. To do this, create an new script named checkMacros.sh, containing the following lines of code:
#!/bin/bash while IFS='' read -r line || [[ -n "$line" ]]; do lines=`find ./ | xargs grep -sw $line | wc -l` echo $line " " $lines done < "$1"
Save it and then make it executable
chmod +x checkMacros.sh
Now run the script
./checkMacros.sh ../mnemonics.txt > ../list1.txt
Last, sort the list1.txt file
cd .. sort -n -k2 list1.txt >list2.txt
Now in the list2.txt you have the list of macro sorted by the number of occurences. The ones for which the occurence is 1 are surely unused.
Note that this method is not exhaustive since you can have some occurrences of a mnemonics into dead code, commented code or other files.
GG1.