In C language, you can use the assert macro to check the truth value of an expression. If the expression evaluates to false, the assert macro will print an error message along with the file name and line number where the assertion failed.

To include the __FILE__ and __LINE__ values in the error message, you can use the following code:

#include <stdio.h>
#include <assert.h>

int main() {
    int x = 5;

    assert(x == 10);

    return 0;
}

In this example, the assert macro checks if the variable x is equal to 10. Since x has a value of 5, the assertion will fail, and an error message will be printed, including the file name and line number where the assertion failed. The output will be something like:

main.c:8: Assertion `x == 10' failed.

Note that the __FILE__ and __LINE__ macros are predefined macros in C that expand to the current file name and line number, respectively

C assert print __FILE__ __LINE__

原文地址: https://www.cveoy.top/t/topic/ifOX 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录