Static and Dynamic assertion debugging, static and dynamic assertion debugging

Source: Internet
Author: User

Static and Dynamic assertion debugging, static and dynamic assertion debugging

Debugging is often required when writing a program. The following describes static and dynamic assertions debugging and common built-in macros.

Built-in macros:

_ FILE _ // output FILE name

_ LINE _ // row
_ DATE _ // DATE
_ TIME _ // TIME
_ FUNCTION _ // FUNCTION name

static_assert(     constant-expression,     string-literal );
Static assertions are used during compilation. Therefore, the value of the first parameter must be determined during compilation, such as the length. If the second parameter is a prompt message. If the expression value of the first parameter is false, an error occurs during compilation and

The second parameter value.

void assert(    int expression );
Dynamic assertions are used when the program is running. If the expression result is false, the program is interrupted.

# Include <iostream> # include <assert. h> using namespace std; void test (int mouth) {assert (mouth >=1 & mouth <= 12 ); // dynamically assert cout <__file __< <endl; // output FILE name cout <__line __< endl; // cout <__date __< <endl; // DATE cout <__time __< endl; // TIME cout <__function __< endl; // function name} int main () {int mouth = 12; static_assert (sizeof (void *) = 4, "64-bit code generation is not supported. "); // static assertions. test (mouth); cin is not supported for 64-bit systems. get (); return 0 ;}


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.