gpt4 book ai didi

c - 未引用类型为 'INVALIDATION_ADDR' 的全局宏 'void' [MISRA 2012 规则 2.5,咨询]

转载 作者:太空宇宙 更新时间:2023-11-04 06:46:03 26 4
gpt4 key购买 nike

我在定义 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;
}

案例二:

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;
}

最佳答案

案例 1:

此诊断:

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

不匹配这个宏:

#define INVALIDATION_ADDRESS   (AddressType)0x12345678U

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

案例 2:

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

您可能希望将源更改为:

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

关于c - 未引用类型为 'INVALIDATION_ADDR' 的全局宏 'void' [MISRA 2012 规则 2.5,咨询],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57917879/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com