Pragma warning [Switch]

Source: Internet
Author: User
Tags deprecated

1 Common Warnings:

# Pragma warning (Disable: 4035) // No Return Value
# Pragma warning (Disable: 4068) // unknown Pragma
# Pragma warning (Disable: 4201) // nonstandard extension used: nameless struct/Union
# Pragma warning (Disable: 4267)
# Pragma warning (Disable: 4018) // signed/unsigned Mismatch
# Pragmawarning (Disable: 4127) // conditional expression is constant
# Pragma warning (Disable: 4146)
# Pragma warning (Disable: 4244) // conversion from 'long _ PTR 'to 'long', possible loss of data
# Pragma warning (Disable: 4311) // 'Type cast': pointer truncation from 'byte * 'to 'ulong'
# Pragma warning (Disable: 4312) // 'Type cast': conversion from 'long' to 'wndproc' of greater size
# Pragma warning (Disable: 4346) // _ it: iterator_category ': Dependent name is not a type
# Pragma warning (Disable: 4786)
# Pragma warning (Disable: 4541) // 'dynamic _ cast' used on Polymorphic type
# Maid (Disable: 4996) // declared deprecated?
# Pragma warning (Disable: 4200) // zero-sized array in struct/Union
# Pragma warning (Disable: 4800) // forcing value to bool 'true' or 'false' (performance warning) 2 common usage:
# Pragma warning (push)
# Pragma warning (Disable: XXXX )//

Code for removing warnings

# Pragma warning (POP)

 

Or:

# Pragma warning (Disable: XXXX)


Code for removing warnings

# Pragma warning (enable: XXXX) // If 'enable' not valid specifier appears, use # pragma warning (default: XXXX) instead.

3. Online materials:

# Pragma support
Developers can use the # pragma command to handle warnings as errors, and enable or disable warnings, as shown in the following example:
# Pragma warning (error: 6260)
# Pragma warning (Disable: 6011)
# Pragma warning (enable: 6056)

 
  • # Pragma warning (Disable: 4996) // disable deprecated warning
    & # Pragma warning (default: 4996)
    What is it?

    1. # pragma warning (Disable: N)
    Set an alarm to invalid
    2. # pragma warning (default: N)
    Set alarm to default
  • When vs2005 is used, the compilation prompts "xxxxxx declared as rejected
    This is a function with check provided by the new C library of MS, with memory overflow detection. It can prevent some program bugs and resist buffer overflow attacks (buffer overflow attack). However, there should be a sacrifice in speed.
    Solution
    1. So if you are sure you are secure, use # pragma warning (Disable: 4996) to eliminate this warning.
    2. We recommend that you use the buffer Security version of _ s instead of simply blocking warnings.
  • # Pragma warning (Disable: 4996) // too many warnings.
  • About # pragma warning
    1. # pragma warning is only valid for the current file (for. H, it is also valid for CPP containing it ),
    It is not effective for all files of the entire project. When the file compilation is complete, the setting will become useless.
    2. # pragma warning (push) stores the current Alert settings.
    # Pragma warning (push, n) stores the current alarm settings and sets the alarm 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. # Set Pragma warning (default: N) 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.