finding unused variable using c

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ssushree shine
    New Member
    • Jul 2012
    • 1

    #1

    finding unused variable using c

    i want to have a program written in c language which will find the unused variables of a c program. my INPUT will be a c file program will search for unused variables. without taking compiler program help.
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    You would basically need to write a full syntactical and lexicon parser for the language to do this (i.e. a compiler with the final output of the compiled code) including preprocessing before you start.

    If you really want to do this, as opposed to using your compiler warnings or getting a 3rd party application (such as PCLint) I suggest you start with something like YACC to build you syntax parser.

    Comment

    • donbock
      Recognized Expert Top Contributor
      • Mar 2008
      • 2427

      #3
      I assume unused variable means variables that are defined but not referenced.

      A full syntactical and lexicon parser is a huge job. Are you sure you want to go there?

      Does your compiler have any switches that cause it to print a symbol table? If so, you could parse the symbol table to find the unused variables.

      There is no standard format for symbol tables so you will have to study the format produced by your compiler and then write a program customized to that format. It is a very good idea to comment your program to clearly identify the kind of symbol tables supported.

      Comment

      Working...