Header file for assertions. More...
#include <stdio.h>#include <stdlib.h>Macros | |
| #define | COMPILE_ASSERT(predicate, file) |
| Asserts a compile-time condition. | |
| #define | ASSERT(predicate, fmt, ...) |
| Asserts a runtime condition with a formatted message. | |
| #define | assert(predicate) |
| Asserts a runtime condition with a default message. | |
Header file for assertions.
This header provides macros for creating compile-time and runtime assertions. Compile-time assertions are useful for validating conditions known during compilation (such as sizeof) and stop the compilation with an error if the conditions are not met.
| #define ASSERT | ( | predicate, | |
| fmt, | |||
| ... ) |
Asserts a runtime condition with a formatted message.
This macro checks a runtime condition (predicate). If the condition is false, it prints an error message to stderr with details about the failed assertion, including the file name, line number, and function name, and then aborts the program. The error message is formatted according to the provided format string and arguments.
| predicate | The condition to assert. Must be a runtime expression. |
| fmt | The format string for the error message. |
| ... | Variadic arguments for the format string. |
Example usage:
| #define assert | ( | predicate | ) |
Asserts a runtime condition with a default message.
This macro checks a runtime condition (predicate). If the condition is false, it prints an error message to stderr with details about the failed assertion, including the file name, line number, and function name, and then aborts the program. The error message is set to "failed".
| predicate | The condition to assert. Must be a runtime expression. |
Example usage:
assert is not already defined and is an alias to the ASSERT() macro with "failed" as default message.| #define COMPILE_ASSERT | ( | predicate, | |
| file ) |
Asserts a compile-time condition.
This macro asserts a compile-time condition. If the condition is false, it generates a compilation error.
| predicate | The condition to assert. Must be a compile-time constant. |
| file | A unique identifier for the assertion, typically the file name. |
Example usage: