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.

variable is used before its value is set



note: this subject is duplicated from http://e2e.ti.com/support/dsp/c6000_multi-core_dsps/f/639/p/331779/1157700.aspx#1157700 (sorry i first missed the compilers category. now i got advised on it.)

initial post:

when compiling for C66/C674x (C6000 v7.4.2) or alternatively for current ARM i am getting a bunch of below warnings. I have enabled much of compiler checks like MISRA options.

"file1.c", line 1002: warning #551-D: variable "f32P" is used before its value is set
"file1.c", line 1003: warning #551-D: variable "f32Pb" is used before its value is set
"file1.c", line 1004: warning #551-D: variable "f32Param" is used before its value is set

the codes do look like this:

float f32P, f32Pb, f32Param;
InitFloat (&f32P);
InitFloat (&f32Pb);
InitFloat (&f32Param);


How can i get rid of that warnings despite disabling them in a global fashion? Is there something like a pragma that i can apply that tells the compiler that those pointer parameter does not need the target memory to be initialized as it is meant to be a return value?


1st response:

I think that the simplest solution is to assign them values in declaration. Something like:

float f32P=0, f32Pb=0, f32Param=0;

Although it is not needed, I think it is better to always initialize variables.

 

2nd response:

doing such init as proposed is impacting badly on performance. you understand, i dont want to add such codes.

its further globbering code with statements that are not needed and thus is also damaging code maintainablity.

furthermore there are international coding standards where you have to explain anything you do in codes. just imaging someone would ever ask me why i am initializing that value to e.g. "0" and not "3.145"...

the main thing is that a sequence like this:

int a, b;
a = b;

does raise warning #551-D with total justification. but the other case does raise the very same warning with only a speculative reasoning. the problem is that its the very same warning number - thus i can not kill the one case whilst keeping the other justified one. i really even dont know which switch enabled that set of speculative warnings as they were not popping up when only using default settings

so i hoped for someone that is understanding the issue a bit better than me. maybe it was not explained clear enough in the initialy where my problem really lives.

 

EDIT: and in a far below follow up:

i was providing "InitF32()" in the sample. in the codes where i get the warning its a much more complex operation than just initisaliation. you might better understand if it were "SetToMuchComplexComputationResult(a,b,c,d,e,&f)" where f is the critical item.