Thread: is there an easy way to find funtions that never get called?

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    19

    is there an easy way to find funtions that never get called?

    i have finished my ai program , and i needs cleaning up , i think there might be some functions that are declared but never called anywere.

    is there an easy way to find them

  2. #2
    Registered User
    Join Date
    Dec 2010
    Posts
    21
    maybe your IDE supports such an function. the best way that comes to my mind would be quote out the functions and see if there is a compiler error.

  3. #3
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    733
    If you don't know what functions are called in your program I think that: you do not make enough comments, or you do not stick to coding conventions, or you do not understand your own code, or your design is bad, or a combination of above.
    There are thousands of functions that are not used (in libraries, especially those header-only like STL/Boost).

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by kmdv View Post
    If you don't know what functions are called in your program I think that: you do not make enough comments, or you do not stick to coding conventions, or you do not understand your own code, or your design is bad, or a combination of above.
    I disagree. Design changes, and a lot of functions that you write end up becoming unnecessary.
    This does not imply bad design. Especially as your program evolves.
    Try keeping track of all functions in a bigger project, and make sure they're all used.

    That said, some functions, especially utility functions are usually useful to keep around.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    733
    Quote Originally Posted by Elysia View Post
    I disagree. Design changes, and a lot of functions that you write end up becoming unnecessary.
    I think that design changes (of course depending what the changes are and how often they come) might be a sign of bad coding.

    I noticed one thing in my programming style: the more expierienced I am, the more portable code I write. I've always had a utility library used everywhere. This library was changing very often at the beginning (had to rewrite it because I could not extend it easily, debugging was hard, etc).
    Now I mostly extend this library, and the more I think how something could be solved, the less time I will spend changing (or even rewriting) it.

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Sometimes they may be. But sometimes you know you have the perfect design only to find that something is missing or something doesn't work and you have to redo it all. Happens only too often.

    Also, I am sure you've seen that the more time passes and the more you learn, the more differently you begin writing your utility code to be more flexible and safe.
    Sometimes you even have the urge to go back and change your older utility functions/classes.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    But sometimes you know you have the perfect design only to find that something is missing or something doesn't work and you have to redo it all.
    Perhaps this is where that statement, "My best code is written with the delete key," comes from.

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Gimpel Software Home Page for PC-lint and FlexeLint for C/C++
    It will find your unused functions, and so much more!
    If you're employed to write software, and you don't have something like this, you're really missing out. It might seem expensive, but the payback is the first bug it finds that you would have spent a day trying to find yourself. Trust me, if you've got a lot of code and you run lint for the first time, you're in for a surprise or two.

    Source Navigator
    Old: Source-Navigator(TM)
    New: BerliOS Developer: Project Summary - Source Navigator NG
    This is just an IDE, but the big advantage is that you can export its cross-reference database as a number of text files. This makes it very easy to write a simple(!) perl script to go looking for particular bits of information.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  9. #9
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    For MSVS right click the fiunction name, object name, variable name, etc. and select Find all references.

    Also you can highlight the desired text and do a find all to find out where that is in the code. This is a simple way to find out if any other code calls a specific function, references an object, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. HOW TO Find right names for GetProcAddress
    By albert3721 in forum Windows Programming
    Replies: 15
    Last Post: 03-16-2010, 07:55 AM
  2. How to find the last value in an array
    By mkanimozhi in forum C Programming
    Replies: 2
    Last Post: 12-05-2009, 10:06 PM
  3. Function to find resolution
    By Bag a Bones in forum C++ Programming
    Replies: 7
    Last Post: 01-19-2006, 12:53 PM
  4. Find Dialog
    By Lithorien in forum Windows Programming
    Replies: 6
    Last Post: 04-25-2005, 05:28 PM
  5. Replies: 2
    Last Post: 11-05-2001, 02:02 PM