Thread: Is there a way to know about .....?

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    147

    Is there a way to know about .....?

    Hello,

    I would like to know if is there a tool, script, source code or similar (one or more) that can tell me:

    * if a function is not used outside is file, so I can declare it static (independently of any define, ie. is never written in other file)

    * if a function is never used (independently of any define, ie. is never written in other file)

    * global variables that are never used

    * a list of where a function is called

    * if a code does not follow an style (i.e. a variable is first upper case when there shouldn't)

    * A function does not have comments over it


    I use MinGW, I dont know if that is important....

    thank you very much
    Last edited by Kempelen; 08-16-2012 at 02:35 PM.

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    There are quite a few different tools to help in analyzing your code. You may want to start by checking out some of the programs in this list of tools for static code analysis.

    Jim

  3. #3
    Registered User ledow's Avatar
    Join Date
    Dec 2011
    Posts
    435
    MinGW uses GCC to compile. Pretty sure that 2 and 3 can be done with just standard warning switches to GCC. 4 could be as simple as a grep (very useful command line tool to have installed): grep func_name( *.c or you'd have to use something that can understand C syntax if you have badly named functions (I know the Eclipse IDE can do that for you, quite easily - Ctrl-Shift-G while highlighting a function or variable, I think). 5 can also be fixed using Eclipse, I think - it has a lot of style-formatting options - but you need a tool that understands C to do it, so simple tricks with grep, sed, etc. won't work. 6 is a bit more tricky but I find some documentation plugins rely on there being comments associated with functions and you could use one of those to do that. And 1 could be something you could do quite easily with Eclipse but it would involve a bit of manual work too.

    More importantly - Why would you need to do those things on a codebase that you had written yourself, and who would care? It's nothing that you wouldn't catch just reading through the code or in the course of normal debugging, for instance and nothing that would affect the operation of the code. And if you used proper design methodologies before you started coding, none of those things would exist anyway.

    Personally, I'd use my normal combination of Eclipse, GCC and sed/grep if I absolutely had to do those tasks, rather than a third-party program. I've never really seen a static code analyser that does a good enough job for things like that and/or that works with modern compilers and mixes of C/C++ etc. Most of them are even achievable without having to know C at all.

    - Compiler warnings are like "Bridge Out Ahead" warnings. DON'T just ignore them.
    - A compiler error is something SO stupid that the compiler genuinely can't carry on with its job. A compiler warning is the compiler saying "Well, that's bloody stupid but if you WANT to ignore me..." and carrying on.
    - The best debugging tool in the world is a bunch of printf()'s for everything important around the bits you think might be wrong.

  4. #4
    Registered User
    Join Date
    Feb 2008
    Posts
    147
    Quote Originally Posted by ledow View Post
    MinGW uses GCC to compile. Pretty sure that 2 and 3 can be done with just standard warning switches to GCC. 4 could be as simple as a grep (very useful command line tool to have installed): grep func_name( *.c or you'd have to use something that can understand C syntax if you have badly named functions (I know the Eclipse IDE can do that for you, quite easily - Ctrl-Shift-G while highlighting a function or variable, I think). 5 can also be fixed using Eclipse, I think - it has a lot of style-formatting options - but you need a tool that understands C to do it, so simple tricks with grep, sed, etc. won't work. 6 is a bit more tricky but I find some documentation plugins rely on there being comments associated with functions and you could use one of those to do that. And 1 could be something you could do quite easily with Eclipse but it would involve a bit of manual work too.

    More importantly - Why would you need to do those things on a codebase that you had written yourself, and who would care? It's nothing that you wouldn't catch just reading through the code or in the course of normal debugging, for instance and nothing that would affect the operation of the code. And if you used proper design methodologies before you started coding, none of those things would exist anyway.

    Personally, I'd use my normal combination of Eclipse, GCC and sed/grep if I absolutely had to do those tasks, rather than a third-party program. I've never really seen a static code analyser that does a good enough job for things like that and/or that works with modern compilers and mixes of C/C++ etc. Most of them are even achievable without having to know C at all.
    Thanks. I was thinking more in a way to do a complete report. Of course I could go function by function to check with that tricks, but that would be endless.
    If this is my code, you ask why?. Because it has 22.000 code lines, and sometime I lost my track. I want a way to do some clean-code without the need to review all those lines.
    I know there are a lot of static analisys tools, but I expected someone who has experience with one of them to point me one or two, because installed them to test it and read all manual and FAQs is a lot of work.
    I am a CodeBlock users but I will give a try to eclipse. What you say sound good.
    Thank you very much

Popular pages Recent additions subscribe to a feed

Tags for this Thread