1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Extract variable definitions and variable use from a C program

Discussion in 'C' started by abk07, Apr 2, 2011.

  1. abk07

    abk07 New Member

    Hi! I’m trying to write a ‘C’ program to extract variable definitions and variable use in each line from a input ‘C’ program.
    That is, a variable is said to be defined when its value changes(including declarations) and it is said to be ‘used’ when it is referenced. I need to consider this for all the cases and functions(built-in as well as user defined)..
    For example consider the following input program

    int main()
    {
    int a,b,c;
    a=10;
    b=20;
    c=a+b;
    printf(“c=%d”,c);
    }

    In the line 3, a,b,c are defined and nothing is referenced, hence in line number 3 under the ‘defined’ column a,b,c must be printed, and a mere ‘–‘ should be printed under the ‘used’ column.
    Similarly in line 6, ‘a’ is defined and both ‘b’ and ‘c’ are used, hence in defined column a should be printed and under ‘used’ column ‘b,c’ should be printed.
    I really don’t know how to start.. can anyone please give me an idea??
    Thanks in advance..
     

Share This Page