[Windows programming] # pragma once and # ifndef... # Define... # Endif comparison

Source: Internet
Author: User
Tags microsoft c

Common methods to prevent header files from being included multiple times in C ++ include:

1) Use the # ifndef... # define... # endif macro

 

# Ifndef _ myheader_h __
# DEFINE _ myheader_h __

 

// Here is my class...

# Endif

 

2) use # pragma once

# Pragma once

// Here is my class...

 

We recommend that you use # pragma once for the following reasons:

1) the code is concise and easy to maintain. # Pragma once is much shorter than # ifndef... and avoids _ myheader_h _ redefinition or # endif inclusion range error.

 

2) Fast compilation. If # ifndef is used, the compiler reads the # include file and parses the code each time. The # pragma once compiler does not open files repeatedly, which greatly improves the efficiency.

The above two points are particularly outstanding in large-scale C ++ projects.

 

Note:# Pragma once is not an international standard, but a function of Microsoft C ++. However, most mainstream C ++ compilers have also implemented this function.

 

 

> Original article copyright belongs to the author, reprint please indicate the source and author information (http://blog.csdn.net/WinGeek/), thank you. <

 

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.