未引用 'void' 类型的全局宏 'INVALIDATION_ADDR' [MISRA 2012 规则 2.5,建议]

global macro 'INVALIDATION_ADDR' of type 'void' not referenced [MISRA 2012 Rule 2.5, advisory]

我在定义 MACRO 但未在代码中的任何地方使用时观察到上述警告。但在某些情况下,我收到了 MACRO 的警告,它也在代码中使用。

我定义了宏 - INVALIDATION_ADDR 并在某些地方使用。但是,我观察到相同的 MISRA 警告。我不确定收到此警告的原因。如何避免此警告。

案例一:

global macro 'INVALIDATION_ADDR' of type 'void' not referenced [MISRA 2012 Rule 2.5, advisory]

lint 规则 755

global macro 'Symbol' (Location) not referenced -- A 'global' macro is one defined in a header file. This message is given for macros defined in non-library headers. The macro is not used in any of the modules comprising the program. This message is suppressed for unit checkout (-u option).

typedef uint32 AddressType;

#define INVALIDATION_ADDRESS   (AddressType)0x12345678U

void fun1()
{
     AddressType Address;
     Address = INVALIDATION_ADDRESS;
}

案例 2:

global typedef 'ConditionsEnumType' of type 'ConditionsEnumType' (line 110, file ITypes.h) not referenced [MISRA 2012 Rule 2.3, advisory]

lint 规则 756

global typedef 'Symbol' (Location) not referenced -- This message is given for a typedef symbol declared in a non-library header file. The symbol is not used in any of the modules comprising a program. This message is suppressed for unit checkout (-u option).

typedef unsigned char       uint8; 
typedef uint8 StateType;

typedef enum
    {
        BLOCK      =  0x80U,
        HEADER     =  0x81U,
        DATA       =  0x82U,    
        OUTCOME    =  0x84U
    } ConditionsEnumType;

/* used in below func */ 
    void fun2()
    {
         StateType state;
         state = (StateType) BLOCK; 
    }

案例一:

此诊断:

global macro 'INVALIDATION_ADDR' of type 'void' not referenced [MISRA 2012 Rule 2.5, advisory]

不匹配这个宏:

#define INVALIDATION_ADDRESS   (AddressType)0x12345678U

所以我认为 MISRA 检查器是正确的,因为您有另一个未引用的宏定义。

案例二:

如果您不使用此类型定义任何变量,ConditionsEnumType 的 typedef 实际上不会被引用。

您可能希望将来源更改为:

void fun2()
{
     ConditionsEnumType state;
     state = BLOCK; 
}