Re: identify unused functions?



On Sun, Mar 30, 2008 at 10:25:05PM +0300, Stefan Kost wrote:
Hi,

Undefined and unused is not the same.

There is NO way to clerify all unused functions in a program.
You could call functions by their addresses and those addresses
could be calculated in runtime. So you don't know...

Something like this...
---<cut>---
int Funk1( void )
{
  printf("Funk1\n"); return(0);
}

int Funk2( void )
{
  printf("Funk2\n"); return(0);
}

main()
{

   int event = -1;
   int (* ptrFunk)( void );

   printf("Event 1 or 2: ");
   fgets( buffer, sizeof( buffer ), stdin );
   event = atoi(buffer);

   switch(event) {
   case 1:
     ptrFunk = Funk2;
     break;
   case 2:
     ptrFunk = Funk1;
     break;
   default:
     printf("No function called\n");
  }

    ptrFunk( );
}
---<cut>---

nm --undefined-only *.o | cut -c12- | sort | uniq
would give you a list of all external symbols

nm --defined-only *.o | cut -c12- | sort | uniq
would give you a list of all defined symbols

now all enties in 2nd list, which are not in first list should be what you are 
looking for ('comm' should be able to do that).

Stefan

Dr. Michael J. Chudobiak schrieb:
Is there any easy way to identify unused functions in source code, for 
cruft reduction?

Using the -Wall flag identifies unused static functions, which is great, 
but it misses the non-static ones.

- Mike

_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

-- 
Göran Hasse

----------------------------------------------------------------
Göran Hasse           email: gorhas raditex se  Tel: 08-6949270
Raditex AB             http://www.raditex.se    
Planiavägen 15, 1tr                             Mob: 070-5530148
131 34  NACKA, SWEDEN                         OrgNr: 556240-0589
VAT: SE556240058901
------------------------------------------------------------------




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]