45aken
45aken

Reputation: 23

"Variable set but not used" error - How to solve?

I get this error, the error is just not for 'stringsix" but for all the declared variables :

assignment42.c:22:9: warning: variable ‘stringSix’ set but not used [-Wunused-but-set-variable]

I just want to pass it from main to functions. I face this problem many times, could someone please tell me an easy to avoid this problem.

int main()
{
char ** listofdetails;
char ** stringOne;
char ** stringTwo;
char ** stringThree;
char ** stringFour;
char ** stringFive;
char ** stringSix;

listofdetails = lineParse();    
printf("%s \n", listofdetails[2]);
stringOne = seperateString1(listofdetails);
stringTwo = seperateString2(listofdetails);
stringThree = seperateString3(listofdetails);
stringFour = seperateString4(listofdetails);
stringFive = seperateString5(listofdetails);
stringSix = seperateString6(listofdetails);
getchar();
return 0;
}

Upvotes: 1

Views: 27711

Answers (2)

Piotr Skotnicki
Piotr Skotnicki

Reputation: 48447

(void)stringSix;

can silence this warning, but this is a bad solution, you should care about warnings.

Upvotes: 10

Some programmer dude
Some programmer dude

Reputation: 409166

First of all it's not an error, it's a warning. Many warnings can be signs of you doing something you should not do (and maybe even cause undefined behavior), but they are not things that will stop the build-process.

As for that specific warning, it's just what it says, you are setting (initializing/assigning to) a variable, but you don't use the variable.

There are two obvious things you could do to not get the warning: Don't do the assignment, or use the variable in an expression.

Upvotes: 11

Related Questions