Why aren't my include guards preventing recursive inclusion and multiple symbol definitions?

前端 未结 3 1335
野趣味
野趣味 2020-11-22 05:35

Two common questions about include guards:

  1. FIRST QUESTION:

    Why aren\'t include guards protecting my header files from mutua

3条回答
  •  一生所求
    2020-11-22 06:11

    First of all you should be 100% sure that you have no duplicates in "include guards".

    With this command

    grep -rh "#ifndef" * 2>&1 | uniq -c | sort -rn | awk '{print $1 " " $3}' | grep -v "^1\ "
    

    you will 1) highlight all include guards, get unique row with counter per include name, sort the results, print only counter and include name and remove the ones that are really unique.

    HINT: this is equivalent to get the list of duplicated include names

提交回复
热议问题