Exforsys
+ Reply to Thread
Results 1 to 2 of 2

Evaluation of Preprocessor Directive

This is a discussion on Evaluation of Preprocessor Directive within the C and C++ forums, part of the Programming Talk category; If I have #define defined as #define dividefunc(a,b) a/b and have a function call as dividefun(x+2,y+3); Suppose x=13 and y=2 ...

  1. #1
    caradoc is offline Senior Member Array
    Join Date
    Apr 2006
    Answers
    122

    Evaluation of Preprocessor Directive

    If I have #define defined as
    #define dividefunc(a,b) a/b

    and have a function call as
    dividefun(x+2,y+3);

    Suppose x=13 and y=2
    How will the #define gets evaluated
    Will it get substituted as
    dividefun(13+2,2+2) which is equal to
    dividefun(15,4)
    and then get divided as 15/4 =4
    or
    will it get evaluated as
    dividefun(x+2,y+2)
    x+2/y+2 which is equal to
    13+3/2+2 which becomes 13+1+2=16

    Kindly let me know how the evaluation takes place


  2. #2
    ashlee is offline Senior Member Array
    Join Date
    Apr 2006
    Answers
    108
    It will get evaluated as
    dividefun(x+2,y+2)
    x+2/y+2 which is equal to
    13+3/2+2 which becomes 13+1+2=16

    This is because whenever a Preprocessor Directive is called the values given in parameters are substituted as such in the calling directive and then only operation takes place.


Latest Article

Network Security Risk Assessment and Measurement

Read More...