1

This rule states that a project should not contain unused tag declarations.

Example:
typedef struct record_s     /* Non-compliant  */    
{
    unsigned short ax;
    unsigned short bx;
} record1_t;


typedef struct             /* Compliant */                      
{
    unsigned short ax;
    unsigned short bx;
} record2_t;

record1_t myRecord1_t;
record2_t myRecord2_t;

How does this makes compliant? What could be the possible issues if there is unused tag declarations?

Lundin
  • 195,001
  • 40
  • 254
  • 396
DJellybean
  • 33
  • 3
  • The general stance for all mission-critical software is that it isn't allowed to contain _anything_ which isn't used. No dead code, no unused variables, no debug left-overs, no commented-out code and so on. One of the main reason why, is that all of these mentioned things are common indications of a quick & dirty patch, or a release which wasn't properly tested. And one of the most common sources of bugs in any software is patches, that fixes something but breaks something else. Another issue is namespace collisions, but that's a less severe problem. – Lundin Sep 22 '22 at 10:46

1 Answers1

0

The Rationale for the Rule is give in The Book:

If a tag is declared but not used, then it is unclear to a reviewer if the tag is redundant or it has been left unused by mistake.

Or to put it simply, if you are defining a tag, but not using is, why are you defining it in the first place?

An unused (and un-needed) tag is harmless... but an unused (but should have been used) tag may cause problems.

The Rule is Advisory, so can be disapplied if necessary. This is particularly applicable if you are adopting existing code (ie a third party header file) that includes tags that were used in the legacy code but are not needed in the new project.

Andrew
  • 2,046
  • 1
  • 24
  • 37