Summary of progma warning in C ++

Source: Internet
Author: User

 

About # pragma warning

1. # pragma warning is only valid for the current file (for. H, it is also valid for CPP containing it), rather than for all files of the entire project. When the file compilation is complete, the setting will become useless.

2. # pragma warning (push)

Store the current Alert settings.

# Pragma warning (push, n)

Store the current Alert settings and set the alert level to n. N is a natural number from 1 to 4.

3. # pragma warning (POP)

Restores the alert settings that were previously pushed into the stack. Any alert settings made between push and pop fail.

4. # pragma warning (Disable: N)

Set an alarm to invalid

5. # pragma warning (default: N)

Set alarm to default

6. Some warnings, such as c4309, take effect from top to bottom. That is, the # pragma warning in the file is traversed from top to bottom, and takes effect in sequence.

For example:

Void func ()

{

# Pragma warning (Disable: 4189)

Char S;

S = 128;

# Pragma warning (default: 4189)

Char C;

C = 128;

}

Then S = 128 will not generate c4309 alarm, while c4309 will generate alarm.

7. Some warnings, for example, c4189, are based on the # pragma warning setting that appears at the end of the function. The other settings for this alarm are invalid.

For example:

Void func ()

{

# Pragma warning (Disable: 4189)

Int x = 1;

# Pragma warning (default: 4189)

}

Then c4189 still appears, because the default command is the last of the function. In other functions in this file, if no resetting is performed, c4189 is also subject to # pragma warning (default: 4189. If you reset it, the last # pragma warning in the function prevails.

8. Some warnings (which msdn considers to be a warning greater than or equal to c4700) take effect only after the function is completed.

For example:

# Pragma warning (Disable: 4700)

Void func ()

{

Int X;

Int y = X;

# Pragma warning (default: 4700)

Int z = X;

}

Y = X and Z = x do not generate c4700 alarms. # Pragma warning (default: 4700) takes effect only in another function after the function is completed.

 

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.