How about preprocessor usage in C....?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • keane
    New Member
    • Mar 2008
    • 13

    How about preprocessor usage in C....?

    Hi everyone,
    i wanna kno bout the preprocessor usage in c... i m a beginner for this, so experts you can judge bout it.thank u
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by keane
    Hi everyone,
    i wanna kno bout the preprocessor usage in c... i m a beginner for this, so experts you can judge bout it.thank u
    What do you want to know about it exactly? (don't say: "how it works" please).
    A preprocessor defines macros and rewrites text in which macros are present
    including optional parameters. Note that a macro under expansion (rewriting)
    is not being expanded further to avoid recursive behaviour. The preprocessor
    properly tokenizes a piece of text for the compiler.

    kind regards,

    Jos

    Comment

    • keane
      New Member
      • Mar 2008
      • 13

      #3
      Originally posted by JosAH
      What do you want to know about it exactly? (don't say: "how it works" please).
      A preprocessor defines macros and rewrites text in which macros are present
      including optional parameters. Note that a macro under expansion (rewriting)
      is not being expanded further to avoid recursive behaviour. The preprocessor
      properly tokenizes a piece of text for the compiler.

      kind regards,

      Jos
      Thank u, i dont need any technical explanation just i wanna kno bout where preprocessor would be more helpful... that means which kinda applications or programs.... Is it really a most effective topic

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by keane
        Thank u, i dont need any technical explanation just i wanna kno bout where preprocessor would be more helpful... that means which kinda applications or programs.... Is it really a most effective topic
        Well, basically using a preprocessor should improve readability of the code and
        should help you in typing consistent code on a very basic level. You can define
        macros that you can use throughout your code. e.g. the following (sloppy) macro
        is a shorthand for the maximum value of two values x and y:

        [code=c]
        #define MAX(x, y) (((x)>(y))?(x): (y))
        [/code]

        ... so instead of typing (or reading!) all those nasty brackets and magic expressions
        you can simply do:

        Code:
        int max= MAX(a, b);
        But note that this macro (as well as many macros) has a flaw, i.e. it evaluates
        the value of the maximum twice and macros hide those facts. More modern
        languages have other solutions instead of preprocessor macros for that.

        kind regards,

        Jos

        Comment

        Working...