MISRA-C++规则8-5-2要求使用正确的大括号初始化C ++结构。我有一个带有联合体的结构,我无法找到正确的大括号组合来满足此规则。我不确定我的代码是否不正确,或者是静态代码分析工具发出了错误的警告。
这是该结构:
typedef struct XMC_VADC_RESULT_CONFIG
{
union
{
struct
{
uint32_t : 16;
uint32_t data_reduction_control : 4; /**< Configures the data reduction stages */
uint32_t post_processing_mode : 2; /**< Result data processing mode. Uses @ref XMC_VADC_DMM_t
For normal operation select
XMC_VADC_DMM_t::XMC_VADC_DMM_REDUCTION_MODE
and data_reduction_control as 0*/
uint32_t : 2;
uint32_t wait_for_read_mode : 1; /**< Allow the conversion only after previous results are read*/
uint32_t part_of_fifo : 2; /**< Make the result register a part of Result FIFO? */
uint32_t : 4;
uint32_t event_gen_enable : 1; /**< Generates an event on availability of new result. */
};
uint32_t g_rcr;
};
} XMC_VADC_RESULT_CONFIG_t;
这是我的初始化代码:
const XMC_VADC_RESULT_CONFIG_t resultConfig =
{
{
{
.data_reduction_control = 0U, // No Accumulation
.post_processing_mode = static_cast<uint32_t>(XMC_VADC_DMM_REDUCTION_MODE),
.wait_for_read_mode = 0U, // Disabled
.part_of_fifo = 0U, // No FIFO
.event_gen_enable = 0U // Disable Result event
}
}
};
我也试过去掉一对大括号,但没有帮助。 正确的大括号数量是多少?