+ Reply to Thread
Results 1 to 2 of 2

Thread: Code fragment gets compiled even if I define a variable to 0. Why?

  1. #1

    Code fragment gets compiled even if I define a variable to 0. Why?

    I have following code:

    Code:
    #define USE_ME_WHEN_NEEDED 0
    
    void IfOrIfDef()
    {
    
    #ifdef USE_ME_WHEN_NEEDED
    	#pragma message("I am compiled!")
    #endif
    }
    Compiler prints "I am compiled!". How?

    Why it compiles the code?

  2. #2
    It is safe to use #if than #ifdef!

    Example:

    Code:
    void IfOrIfDef()
    {
    #if USE_ME_WHEN_NEEDED
    	#pragma message("I am compiled!")	
    #endif
    }

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts