Some Usage of the pre-compiled macro definition of C [accumulating]

Source: Internet
Author: User

Header file to prevent repeated inclusion

======================

According to # define and condition compilation # ifdef, # ifndef # else # The most common use of endif is to prevent repeated inclusion of header files.

However

# Pragma once

Better. Now GCC cl.exe supports not onlyCodeLess, and no macro name is required. It is better.

# Pragma description of compiler information // complex usage, refer to the http://baike.baidu.com/view/1451188.htm

# Warning display compilation warning information

# Error show compilation error information

Reminders under certain conditions can be provided during compilation of these conditions. For example, if the defined macro is not defined, # error is used to stop compilation.

 

Multiple conditions in Conditional compilation and multiple macros can be used to determine simultaneously

================================

Conditional compilation is also in progress, for example, determining the two conditions at the same time

# How should I write ifdef (A & B? If it is ifdef or ifndef, this cannot be written.

It must be written in the format of # If (A = 1 & B = 2. Try removing # define B 2, and the compilation information and output in the condition will not be displayed.

# Include <stdio. h># Include <Iostream> Using   Namespace  STD;  Int Main ( Int Argc, Char ** Argv) {cout < "  Main  " < Endl;  # Define A 1 # Define B 2//  # Ifdef A & # ifdef B      # If (A = 1 & B = 2) # Pragma Message ("\ npragma message Yes defined a B \ n ") Cout < "  Yes defined a and B ??  " < Endl;  # Endif      Return   0  ;} 

Ifdef can also be found to have multiple conditions:

similar to: # If defined _ debug | defined vld_force_enable

//As you can see in PWD. c In the source code (sf.net link) of Boost-jam-3.1.18, we have accumulated.//It seems that Cl also defines the NT variable. GNU gcc defines _ gnuc __/*Mingw on Windows declares path_max in limits. h*/# IfDefined (NT )&&! Defined (_ gnuc __)# Include<Direct. h># DefinePath_max _ max_path# Else# Include<Unistd. h># IfDefined (_ como __)# Include<Linux/limits. h># Endif# Endif

 

 

 

VLD is a programming toolkit for detecting memory leaks. Recommended! I don't know what to do if I encounter a segment error or the memory is not properly released. Use this. Segment errors do not seem to be able to be effectively detected .. Wild pointer!

 

 

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.