Preprocessor directives

This is a discussion on Preprocessor directives within the C Programming forums, part of the General Programming Boards category; hey guys i came across this Code: #define LCD_E(x) ((x) ? (IOSET1 = PIN_E) : (IOCLR1 = PIN_E) ); i ...

  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
    20,981
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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,796
    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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21