我有这样的定义:
static const char* STRING_ARRAY[NUM_UNITS] = STRING_ARRAY_VALUES;什么时候
#define STRING_ARRAY_VALUES \
{ "n/a", \
"bool", \
... \
}不幸的是,它不符合MISRA-C++规则8-5-2:
"MISRA-C++ Rule 8-5-2 (required): Braces shall be used to indicate and match the
structure in the non-zero initialization of arrays and structures."有人能给我解释一下为什么它不符合要求吗?我认为#define命令会将定义转换为类似以下内容:
static const char* STRING_ARRAY[NUM_UNITS] = {"n/a", "bool",...}这符合MISRA的规则。
有没有办法在保留#define的同时使其符合MISRA
发布于 2013-03-01 22:30:58
有两种可能的原因:
,
sizeof(STRING_ARRAY)/sizeof(const char*) == NUM_UNITS,这是一个很好的做法,不管MISRA如何。https://stackoverflow.com/questions/15138749
复制相似问题