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
}
}
};
我也尝试过删除一组牙套,但这没有帮助。 大括号的正确数量是多少?
答案 0 :(得分:2)
const XMC_VADC_RESULT_CONFIG_t resultConfig = { 0u };
.name
语法)是C事物,仅在C99和更高版本中存在。 MISRA-C:2004中不允许使用它们,但MISRA-C:2012中(其中有一些特殊规则)不允许使用它们。在C ++中,它们只是在最近才引入,不允许在MISRA兼容应用程序中使用C ++版本。union
类型的修剪,特别是在C ++中,它是未定义的行为,尤其是不允许。 C中存在该规则的一些例外,但C ++中没有。摘要:您不能在任何形式的MISRA应用程序中使用此代码。删除并集和位字段,并用按位运算符和位掩码替换它们。
答案 1 :(得分:0)
C ++没有designated initializers until C++20,因此您将其删除。
Ext.onReady(() => {
Ext.create({
xtype: 'cartesian',
renderTo: element, // rendered element
height: 200,
insetPadding: 20,
store: {
fields: ['name', 'amount'],
data: [..] // data
},
smooth: true,
axes: [{
type: 'category',
position: 'bottom',
fields: ['name'],
label: {
fill: 'rgba(0,10,30,.75)',
fontSize: 15
},
style : {
strokeStyle : 'rgba(0,10,30,.2)'
}
}],
series: [
{
type: 'line',
fill: true,
style: {
fill: '#a2d5f2',
fillOpacity: .6,
stroke: '#00a1fd',
strokeOpacity: .6,
},
tooltip: {
trackMouse: true,
renderer: (tooltip, model, item) => {
const content = item.record.data.name + ': ' + item.record.data.amount
//tooltip.setHtml(model.get(item.field));
tooltip.setHtml(content)
}
},
xField: 'name',
yField: 'amount',
marker: {
type: 'circle',
radius: 5,
lineWidth: 2,
fill: '#fff',
fillOpacity: 1,
},
renderer: (sprite, config, rendererData, index) => {
let store = rendererData.store,
storeItems = store.getData().items,
previousRecord = storeItems[index],
currentRecord = (index > 0 ? storeItems[index - 1] : previousRecord),
current = currentRecord && parseFloat(currentRecord.data['amount']),
previous = previousRecord && parseFloat(previousRecord.data['amount']),
changes = {};
switch (config.type) {
case 'marker':
if (index == 0) {
return null; // keep the default style for the first marker
}
changes.strokeStyle = (current >= previous ? '#00a1fd' : 'red');
//changes.fillStyle = '#fff';
//changes.fillOpacity = 1;
//changes.lineWidth = 2;
break;
case 'line':
changes.strokeStyle = (current >= previous ? '#00a1fd' : 'red');
changes.lineWidth = 2;
changes.fillStyle = (current >= previous ? '#a2d5f2' : 'red');
changes.fillOpacity = (current >= previous ? 1 : .1);
break;
}
return changes;
}
}]
});
})