C ++ removes unnecessary compilation warnings

Source: Internet
Author: User
  • When using C ++, to avoid empty Catch, we often specify the Exception ex parameter, but this parameter is often not used. The compiler will give a warning about unused variables, use # pragma warning to eliminate unnecessary warnings.

About # pragma warning

  • # 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.
  • # 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.
  • # Pragma warning (pop)
    • Restores the alert settings that were previously pushed into the stack. Any alert settings made between push and pop fail.
  • # Pragma warning (disable: n)
    • Set an alarm to invalid
  • # Pragma warning (default: n)
    • Set alarm to default
  • 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.

  • Some warnings, such as C4189, are based on the # pragma warning setting that appears at the end of the function. The other settings for this alarm are invalid.

    • Example: void func (){

      • # Pragma warning (Disable: 4189) int x = 1; # pragma warning (default:
        4189)

      } Then c4189 will still appear, 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.

  • Some warnings (which MSDN considers to be a warning greater than or equal to C4700) take effect only after the function is completed.
    • Example: # pragma warning (Disable: 4700) void func ()

{

  • Int x; int y = x;

    • # Pragma warning (default: 4700)

      • Int z = X;

    } Then neither y = x nor z = x will generate the c4700 alarm. # Pragma warning (default: 4700) takes effect only in another function after the function is completed.

Warning LNK4006: NULL_IMPORT_DESCRIPTOR already defined

Solution: If you compile a static library, delete all the databases in 'additional Dependencies.

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.