10-01-2018, 01:15 PM
struct Test
{
char str1[20];
char str2[20];
};
struct Test t =
{
"Hello",
"World"
};
LDRA flags this with 397 S (Array initialisation has insufficient items.) violation of 8-5-2 (Braces shall be used to indicate and match the structure in the non-zero initialization of arrays and structures.)
Looking at the details of the rule in the guidelines, I see why: "The non-zero initialization of arrays or structures requires an explicit initializer for each element."
It seems there should be an exception for initializing a character array with the string syntax, since:
a. the unused characters are implicitly null character 0
b. there is no MISRA compliant way to explicitly add null characters to a "string"
I think MISRA C 2004 has a similar problem, but I haven't looked at 2012 yet.
{
char str1[20];
char str2[20];
};
struct Test t =
{
"Hello",
"World"
};
LDRA flags this with 397 S (Array initialisation has insufficient items.) violation of 8-5-2 (Braces shall be used to indicate and match the structure in the non-zero initialization of arrays and structures.)
Looking at the details of the rule in the guidelines, I see why: "The non-zero initialization of arrays or structures requires an explicit initializer for each element."
It seems there should be an exception for initializing a character array with the string syntax, since:
a. the unused characters are implicitly null character 0
b. there is no MISRA compliant way to explicitly add null characters to a "string"
I think MISRA C 2004 has a similar problem, but I haven't looked at 2012 yet.
<t></t>