[C ++] Static detection of printf Compiler

Source: Internet
Author: User

The format string of C is often used. The gcc/clang extension can detect strings and variable parameters. If the parameters do not match, the warning will pop up.

If it is manually written, you need to add a bit of code, otherwise it will not be detected.

1. variable parameters

Void my_printf (const char * format ,...)_ Attribute _ (format (printf, 1, 2 )))

1 indicates the subscript of the parameter where the format string is located (starting from 1 );

2 indicates the subscript starting with the variable parameter.

2. va_list

Void my_print (const char * format, va_list args)_ Attribute _ (format (printf, 1, 0 )))

If it is va_list, enter 0 in the second index.

3. this call

This call, such as C ++,This is the first function member.Don't forget this.

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.