Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check for unused members in struct?

If I declare and never use variable then gcc will give me a warning.

But if I have a struct with several members and some of those are not used, gcc will not warn about it...

Is there an option (or another method) to check these?

(Of course I can manually delete some entries and try to compile again, but I am looking for this kind of approach).

Thanks

like image 955
skeept Avatar asked Nov 02 '10 16:11

skeept


1 Answers

No GCC won't warn about this. Mostly because in the majority case whether or not a member is used can't be determined. A good portion of struct are defined in a header file. This can be used by not just your application but by any other application referencing your .lib or using the same header file. Hence just because the current piece of code being compiled doesn't use the member it doesn't mean that the member is not used by some other piece of code.

Local variables are different. Whether or not they are used easily determined by compiling only the function in question. Hence GCC, and many other compilers, give a warning.

like image 123
JaredPar Avatar answered Oct 03 '22 21:10

JaredPar