Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
856 views
in Technique[技术] by (71.8m points)

static analysis - C++ Code Smell: Incorrect Initializer Braces Placement

I am trying to fix the following code smell within my C++ code generated from Klocwork(KW):

MISRA.INIT.BRACES: Incorrect initializer braces placement

Below is a snippet of the code I am attempting to clean this up on.

    typedef char charString[10];

    enum SomeEnum
    {
        BLAH1_e,
        BLAH2_e,
        BLAH3_e
    };

    struct ParentStruct
    {
        SomeEnum myEnumValue;
        charString myCharStringValue;
    };

    // This is the the part that KW is not happy about
    // KW complaining about initializer bracer placement
    const ParentStruct myParent[3] = 
    {
        {BLAH1_e, "String1"},
        {BLAH2_e, "String2"},
        {BLAH3_e, "String3"}
    }

I've attempted many variations of bracer placement and can't seem to figure out the exact issue with bracer placement I currently have. This doesn't generate any compile errors nor does this have a negative outcome on the code. Maybe it's just KW but just wanted to get some thoughts before I give up completely.

Below is an alternative bracer placement I attempted as well in case someone throws it out as an answer:

    // compiles but KW does not like this as well
    const ParentStruct myParent[3] = 
    {
        {BLAH1_e, {"String1"}},
        {BLAH2_e, {"String2"}},
        {BLAH3_e, {"String3"}}
    }

    
question from:https://stackoverflow.com/questions/65895136/c-code-smell-incorrect-initializer-braces-placement

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...