Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
859 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 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...