Reputation: 549
Iam writing a program in C. Is there any way(gcc options) to identify the unused code and functions during compilation time.
Upvotes: 2
Views: 423
Reputation: 363517
gcc -Wall
will warn you about unused static
functions and some other types of unreachable code. It will not warn about unused functions with external linkage, though, since that would make it impossible to write a library.
Upvotes: 3
Reputation: 71060
No, there is no way to do this at compile time. All the compiler does is create object code - it does not know about external code that may or may not call functions you write. Have you ever written a program that calls main
? It is the linker that determines if a function (specifically, a symbol) is used in the application. And I think GCC will remove unused symbols by default.
Upvotes: 1
Reputation: 272467
If you use -Wunused-function
, you will get warnings about unused functions. (Note that this is also enabled when you use -Wall
).
See http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html for more details.
Upvotes: 4