Thread: Preprocessor directives

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    21

    Preprocessor directives

    hey guys i came across this

    Code:
    #define LCD_E(x)              ((x) ? (IOSET1 = PIN_E)  : (IOCLR1 = PIN_E) );
    i know that it is macro expansion but wat does the expression in the brackets mean?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    It is the ternary operator. If x evaluates to true, the result of the operation is (IOSET1 = PIN_E), otherwise it is (IOCLR1 = PIN_E). Incidentally, the semi-colon at the end of the macro looks like it should not be there.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    On a completely unrelated note:

    [] = Brackets
    {} = Braces
    () = Parens (parentheses)

    As it is, one can figure out what you meant, but saying "brackets" when you mean "parens" can be confusing if both are present in the expression.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed