Thread: difference between if and #if

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    39

    difference between if and #if

    what is the difference between if and #if. when to use what?

    thanks in advance

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    #if is done before the compiler sees the code, so it has to be a constant known before you even start compiling the code. This is typically selecting different variants of the same code (e.g. #if WINDOWS ... #elsif LINUX ... #else ... ).

    if is done during the runtime of the application, so it can do "anything" [although if you write something like if(x) and the compiler can know FOR SURE that x will always be non-zero, it may of course skip the test of x, and always execute the code anyways].

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