0

I have writtern some code but apparently i have not initalised two parts of it, now to my knowledgde i have and i can not see why it is showing warnings for it. i hope you can help.

double m, l, dm, dc, xsq, D;
	
	W_line_Sum(line ,t);
	W_line sums;
	D = ((  sums.w * sums.xx) -( pow(sums.x,2)));
	m = ((sums.w) * sums.xy) - (sums.x*sums.y) / D;
	dm = sqrt( sums.w/D ) ;
	l = ((sums.y* sums.xx) - (sums.x * sums.xy)) / D;
	dc = sqrt(sums.xx /D )  ;
	xsq = sums.v2;
void W_line_Sum(W_line* a, int t){		
	W_line sums;
	for (int i=0; t<b; ++i){
	
	sums.x+= a[i].x;  
	sums.y+=a[i].y;
	sums.xx+=a[i].xx;
	sums.xy+=a[i].xy;
	sums.w+=a[i].w;
	sums.xw+=a[i].w*a[i].x;
	}
	
}

for both of these bits the warning that is popping up is this;
warning C4700: uninitialized local variable 'sums' used

3
Contributors
4
Replies
5
Views
8 Years
Discussion Span
Last Post by Salem
0

Variable sums in the second code snippet is being used before it has been initialized. Look on line 5: what is the initial value of sums.x? Answer: its unitialized and could contain any random value. So the initial result of line 5 is undefined because we don't know the value of sums.x.

To correct the problem, you need to add one or more lines between line 2 and 3 that initializes all values in the sums variable:

sums.x = 0;
sums.y = 0;
// etc etc for each member of that structure
0

i have done that but the warning si still coming up for the first bit

double m, l, dm, dc, xsq, D;
	
	W_line_Sum(line ,t);
	W_line sums;
	D = ((  sums.w * sums.xx) -( pow(sums.x,2)));
	m = ((sums.w) * sums.xy) - (sums.x*sums.y) / D;
	dm = sqrt( sums.w/D ) ;
	l = ((sums.y* sums.xx) - (sums.x * sums.xy)) / D;
	dc = sqrt(sums.xx /D )  ;
	xsq = sums.v2;

is still producing a warning.
warning C4700: uninitialized local variable 'sums' used

0

Did you read my previous post? Did you understand it? That code has the same identical problem as the first one you posted here.

0

You've got this

W_line sums;
	D = ((  sums.w * sums.xx) -( pow(sums.x,2)));

Imagine this

W_line sums = { uninitialised, garbage, here };
	D = ((  sums.w * sums.xx) -( pow(sums.x,2)));

What is the value of D given the rubbish you calculate with?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.