Thread: Use of "?" ":"

  1. #1
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300

    Use of "?" ":"

    What's this:
    Code:
     q = (q->next == oldhead ? NULL : q->next);
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  2. #2
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    it means
    Code:
    if (q->next == oldhead) 
        q = NULL;
    else 
        q = q->next;

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Ah...thanks
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  4. #4
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    And it's called a ternary operator :-)

  5. #5
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    These are handy for when you wish to annoy people with hard to follow code. I do use them a lot of the time though... Just do not get carried away with them since they really do make your code more difficult on others.

  6. #6
    HelpingYouHelpUsHelpUsAll
    Join Date
    Dec 2007
    Location
    In your nightmares
    Posts
    223
    Frequent use of these & a lack of/poor use of white space & you have all the standards evident in Obfuscated C Code.
    long time no C; //seige
    You miss 100% of the people you don't C;
    Code:
    if (language != LANG_C && language != LANG_CPP)
        drown(language);

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by P4R4N01D View Post
    Frequent use of these & a lack of/poor use of white space & you have all the standards evident in Obfuscated C Code.
    You missed:
    Using O and l as variables - preferrably sequences of O0 and l1's.
    Heavily using macros.
    Using indexing the "wrong way around" and on string literals.

    You must have at least 3 out of the 5 to qualify.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. parse error before "{" token
    By getout in forum C Programming
    Replies: 4
    Last Post: 12-31-2006, 01:26 PM
  2. "::" in Mac Classic file system
    By dwks in forum Tech Board
    Replies: 2
    Last Post: 08-04-2006, 08:46 PM
  3. strtok with "" as delimiter?
    By fanoliv in forum C Programming
    Replies: 15
    Last Post: 06-19-2006, 12:44 PM
  4. Replies: 3
    Last Post: 11-11-2003, 03:44 AM
  5. "?" and ":"
    By EvBladeRunnervE in forum C Programming
    Replies: 5
    Last Post: 02-04-2003, 12:13 AM