C + + debugging Help

Source: Internet
Author: User

ASSERT preprocessing macros

Assert is a preprocessing macro, so-called preprocessing is actually a preprocessing variable that behaves like an inline function, and an Assert macro uses an expression as its condition:

ASSERT (expr)

The first is to evaluate expr, and if its value is false, assert the output information and terminate the execution of the program, and do nothing if true . The Assert macro is defined in the cassert header file , because it is a macro, so there is no scope and namespace for the argument to be used directly. You do not need to include namespaces.

As with pre-processing variables, the macro name must be unique within the program, and the program containing the Cassert header can no longer define variables, functions, etc. called Assert.

ndebug preprocessing variables

The behavior of an assert depends on the state of a preprocessing variable named ndebug , and if ndebug is defined, the Assert does nothing, and by default there is no Ndebug defined, at which point the assert performs a run-time check, which compares the side

Then, when we do not need to Asser check, do not need to delete the previous Assert statement, as long as the #define NDEBUG .

In addition to the use of assert, we can also use Ndebug to define their own debug code, mainly in the code to do ndebug preprocessing variables are defined by the judgment on it!

void print (int ia[], size_t size) {      #ifndef ndebug          ..... #endif    

The C + + compiler provides the _ _func_ _ variable, we can output the name of the current debug function, and the preprocessor also defines the following name:

_ _file_ _/    / The string literal of the file name _ _line_ _   /    //////////////////////// 

This allows us to export more and more detailed information when we define our own debug code.

C + + debugging Help

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.