This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

C2000-CGT: about warning of #552-D variable was not set but never used

Expert 2831 points
Part Number: C2000-CGT
Other Parts Discussed in Thread: C2000WARE

Tool/software:

Hi

My customer find rediculous warning.

We use TI's compiler v22.6.1.LTS.

In custome project (Besed on C2000ware 5.0x.00.00 and TIDM_1001 sample project), there is warnings of #552-D variable "msgCtrl" was set but never used can.c .

So I try coment-out the declaration of msgCtrl.

However, After comment-put, it occors #20 identifier "msgCtrl" is undefined can.c.

It rediculous, first say "it never used" but it was used!

Is this compiler bug?

I can send the CCS project in provate chat, please reply comment (I will request firendship)

Thanks,

GR

  • There's nothing ridiculous here.

    The "set but never used" warning says you are assigning a value to a variable but no other code refers to. It's a dead code warning. You should remove dead code. In the example, x is set but never used and therefore x has no purpose.

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    int x;
    int main(void)
    {
    x = 2;
    }
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    To remove all warnings, delete lines 1 AND 6.

  • Hi Kier,

    Thanks for your information.

    I understand the details of the error.

    But, In my customer's code, msgCtrl is used in if()'s judgment condition.

    So I could not explain/understand why the erroe exist.

    Best reagrds,

    GR

  • But, In my customer's code, msgCtrl is used in if()'s judgment condition.

    OK but you didn't mention this is your OP.

    I guess only TI can help you.

  • This can happen if you assign a value and never read from the variable. I suppose there are some situations where you do read it, but the compiler can't figure it out.

    I think it also happens if you init it to some value and then set it in code before it is read, that makes the init useless.

  • Hi everyone,

    Thank you for information.

    In my reserch, some of function that read msgCtrl was for debug.
    In state that not for debug, it was not reading the variable by precompiler.

    Best regards,

    GR