Detailed description of C/C ++ Conditional compilation

Source: Internet
Author: User

 

1

 

# Ifdef _ XXXX

 

... Procedure 1...

 

# Else

Www.2cto.com

... Procedure 2...

 

# Endif

 

This indicates that if the identifier _ XXXX has been defined by the # define command, the program segment 1 will be compiled; otherwise, the program segment 2 will be compiled.

 

2

 

# Ifndef _ XXXX

 

... Procedure 1...

 

# Else

 

... Procedure 2...

 

# Endif

 

# Ifndef is used here, indicating if not def. of course, it is the opposite of # ifdef (if the identifier _ XXXX is not defined, the execution segment 1; otherwise, the execution Segment 2 ).

 

3

 

# If constant

 

... Procedure 1...

 

# Elif <constant expression 2>

 

... Procedure 2...

 

# Elif <constant expression 3>

 

... Program Section 3...

 

......

 

# Else

 

... Procedure 2...

 

# Endif

 

It indicates that if the constant is true (not 0, whatever number, as long as it is not 0), the program segment 1 will be executed; otherwise, the program segment 2 will be executed.

 

For example:

 

1.

 

# If defined (_ PC) & defined (_ SSE)

 

# Ifdef DEBUG

 

# Define _ PC_VERIFY_ALIGNMENT __

 

# Endif

 

# Ifdef _ PC_VERIFY_ALIGNMENT __

 

# Define PC_VERIFY_ALIGN_ASSERT (ptr )\

 

{\

 

If (INT) ptr) % 16 )! = 0 )\

 

{\

 

Debugf (NAME_Critical, TEXT ("Unaligned PC data (0x % X)"), ptr );\

 

DebugBreak ();\

 

}\

 

}

 

# Else

 

# Define PC_VERIFY_ALIGN_ASSERT (ptr)

 

# Endif

 

# Else

 

# Define PC_VERIFY_ALIGN_ASSERT (ptr)

 

# Endif

 

2.

 

# Define ABC 3

 

Main ()

 

{

 

# If ABC> 0

 

Int a = 1;

 

Printf ("% d \ n", );

 

# Elif ABC <0

 

Int B =-1;

 

Printf ("% d \ n", B );

 

# Else

 

Int c = 0;

 

Printf ("% d \ n", c );

 

# Endif

 

}

From 360 Knowledge Network

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.