Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12616 Discussions

Compiler not detecting unused functions

Altera_Forum
Honored Contributor II
1,018 Views

I recently inherited a project and I am trying to clean it up. I have the following warnings enabled but I don't think the unused functions are being detected or at least reported by the compiler.  

 

-Wall -Wunused -Wunused-function -Wextra 

 

 

Here's a the build command for one of the source files 

 

nios2-elf-gcc -xc -MP -MMD -c -I../gsi_proc_bsp//HAL/inc -I../gsi_proc_bsp/ -I../gsi_proc_bsp//drivers/inc -DSYSTEM_BUS_WIDTH=32 -pipe -D__hal__ -DALT_NO_C_PLUS_PLUS -DALT_NO_CLEAN_EXIT -D'exit(a)=_exit(a)' -DALT_NO_EXIT -DALT_NO_INSTRUCTION_EMULATION -DALT_STACK_CHECK -fstack-check -DALT_SINGLE_THREADED -DALTERA_AVALON_UART_USE_IOCTL -O1 -g -Wall -Wunused -Wunused-function -Wextra -mhw-div -mcustom-fpu-cfg=60-1 -mhw-mul -mno-hw-mulx -o obj/default/.metadata/.plugins/org.eclipse.cdt.make.core/specs.o .metadata/.plugins/org.eclipse.cdt.make.core/specs.c 

 

 

 

I just to test the compiler flag I added the following function, and the compiler detects the unused variable, but not the unused function! 

 

void MyUnusedFunction(void) { int i; printf("I do nothing\n"); }  

Any ideas?
0 Kudos
2 Replies
Altera_Forum
Honored Contributor II
312 Views

Because your function is not defined as static void it could be used in other files. Since the compiler looks at only one file at a time it has no way of knowing if this is the case.

0 Kudos
Altera_Forum
Honored Contributor II
312 Views

Thanks, the fun of a different compiler.

0 Kudos
Reply