Why do I get an error, error: variable 'sum_r' set but not used [-Werror,-Wunused-but-set-variable] when I set the variables sum_r sum_g, and sum_b in a for loop then try to change their values later in another for loop?
Here is my current code:
// Blur image
void blur(int height, int width, RGBTRIPLE image[height][width])
{
RGBTRIPLE new[height][width];
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
int sum_r = 0;
int sum_g = 0;
int sum_b = 0;
for (int ji = i - 1; ji < 3; ji++)
{
for (int jj = j - 1; jj < 3; jj++)
{
int rgb_r = image[ji][jj].rgbtRed;
int rgb_g = image[ji][jj].rgbtGreen;
int rgb_b = image[ji][jj].rgbtBlue;
sum_r += rgb_r;
sum_g += rgb_g;
sum_b += rgb_b;
}
}
}
}
return;
}
I have tried using pointers and addresses but I cannot seem to figure it out. Could someone explain why this is happening?
>Solution :
- You do not need
returnin avoidfunction - You are getting this message because you set those variables in the loop but you do not use it. Your function can be reduced to the no-op and the compiler is warning that you forgot to do something with your value.
optimizing compilers will rescue this function to:
void blur(int height, int width, RGBTRIPLE image[height][width])
{
}
https://godbolt.org/z/cEeejGKrh