# Pragma usage

Source: Internet
Author: User

Among all the pre-processing commands, the # pragma command may be the most complex. Its function is to set the compiler status or instruct the compiler to complete some specific actions. this command provides a method for each compiler to provide host or operating system-specific features while maintaining full compatibility between C and C ++ languages.

# Pragma message ("message text ")
When the compiler encounters this instruction, the message text is printed out in the compilation output window. when many macros are defined in the program to control the source code version, we may forget whether these macros are correctly set. At this time, we can use this command to check the macros during compilation. suppose we want to determine if we have defined _ x86 macro in the source code. The following method can be used:
# Ifdef _ x68
# Pragma message ("x68! ")
# Endif

# Pragma code_seg (["section-name" [, "section-class"]): it can set the code segment where function code is stored in the program, when we start the driver, we will use it.

# Pragma once ensures that the header file is compiled only once

# Pragma hdrstop
Indicates that the header file after the pre-compiled header file is not pre-compiled.

# Pragma startup specifies the compilation priority
# Pragma resource "*. DFM" indicates adding resources in the *. DFM file to the project. DFM includes the definition of the form appearance.

# Pragma Waring (Disable: 4507 34; once: 4385; error: 164) is equivalent:
# Pragma warning (Disable: 4507 34) // No 4507 and 34 Warnings are displayed
# Pragma Waring (once: 4385) // only one warning is reported once
# Pragma Waring (error: 164) // use the 164 warning as an error.

# Pragma warning (push [, N]) // here n represents a warning level (1--4)
# Pragma warning (POP)

# Pragma warning (push) // Save the existing warning status of all warning information
# Pragma warning (push [, N]) // Save the existing warning status of all warning information and set the global warning level to n
# Pragma warning (POP) // The Last warning message pops up to the stack. All changes made between the inbound and outbound stacks are canceled from the previous settings.

# Pragma comment (.....) // This command puts a comment record into an object file or execution file. Common lib keywords can help us to connect to a library file, such:
# Pragma comment (Lib, "user32.lib") // Add user32.dll to this project

# Pragma pack (n), the compiler will be aligned according to n Bytes
# Pragma pack (), the compiler will cancel the custom byte alignment.

Structure alignment:
(01) each member is aligned in its own way and can minimize the length.
(2) The default alignment of complex types draws the alignment of its longest Member
(3) The alignment length must be an integer multiple of the largest alignment parameter in the member, so that each item can be aligned when processing the array.
The alignment boundary must be: 1 2 4 8 16 32 64 ......





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.