Re: variable ‘something’ set but not used [-Wunused-but-set-variable]

Mahmood Naderan nt_mahmood@yahoo.com
Tue Jul 12 18:36:00 GMT 2011


Hi all,
I don't know why I don't receive emails from gcc-help correctly.
In the archive I saw Axel Freyn replied this:


Gcc is right, the warning is appropriate.
gcc tells you that fullpath_length is not necessary, because while you
ASSIGN a value to it ("variable ... set"), you NEVER READ that value
("but not used").
And in your example code: Imagine we would simply remove
fullpath_length, and replace the last line by "strlen(fullpath);", then
your code would behave exactly as before. 
So why do you have this variable fullpath_length? if you don't want that kind of warning, compile with the flag
-Wno-unused-but-set-variable 

Thanks Axel, I understand. I commented fullpath_length = strlen(fullpath); 
and there is no problem with that

Thanks 





// Naderan *Mahmood;


----- Original Message -----
From: Andrew Haley <aph@redhat.com>
To: Mahmood Naderan <nt_mahmood@yahoo.com>
Cc: gcc <gcc-help@gcc.gnu.org>
Sent: Tuesday, July 12, 2011 10:43 PM
Subject: Re: variable ‘something’ set but not used [-Wunused-but-set-variable]

On 07/12/2011 07:12 PM, Mahmood Naderan wrote:
>> The message is correct.  fullpath_length is set, but not used.
>  
> Hi
> What is this then
> 
>      fullpath_length = strlen(fullpath);     // variable is used here
> 
> isn't a usage of fullpath_length?

No, it's not.  It's a set of fullpath_length.

Andrew.



More information about the Gcc-help mailing list