encyclopegia.org

Assert.h

is a header file in the C standard library. It defines the C preprocessor macro and implements runtime assertion in C. is defined in ANSI C as part of the C standard library. In the C++ programming language, and are available; both are functionally equivalent.

is a header file in the C standard library. It defines the C preprocessor macro and implements runtime assertion in C. is defined in ANSI C as part of the C standard library. In the C++ programming language, and are available; both are functionally equivalent. ==Use== The macro implements runtime assertion. If the expression within it is false, the macro will print a message to stderr and call abort() , defined in . The message includes the source filename and the source line number from the macros and , respectively. Since C99, the name of the function the assert statement is included as ( ) and the expression itself. In ANSI C, the expression in the macro is defined as signed integer, although any expression that can be implicitly cast to a signed integer may be used. In C99, the macro explicitly allows any scalar type. Two common uses of the macro are to assert that a pointer is not null and to ensure that an array index is in-bounds. Below is a program using the macro. This program will always evaluate as false, as is a null pointer and does not point to a valid memory location: include include int main() { void* ptr = NULL; assert(ptr); return 0; } Upon compiling the program and running it, a message similar to the following will be output: program: source.c:5: main: Assertion 'ptr' failed. Aborted (core dumped) The definition of the macro changes depending on the definition of another macro, . If is defined as a macro name, the macro is defined as , thus resulting in the macro not evaluating the expression. The use of may affect the overall behavior of a program if one or more statements contain side effects, as these statements are not evaluated. The macro does not include an error message. However the comma operator can be used to add it to the printed expression, as in . === === The keyword, added in C++11, serves a similar purpose to the macro. Unlike the macro, runs at compile-time rather than at runtime. The original implementation used template hacks. The keyword takes in a constant expression that can be converted into a Boolean and a string literal; if the expression fails, the string literal is returned, otherwise, the assertion has no effect. In C++17, this assertion failure message was made optional, and the subsequent message is omitted if not specified. In C11, the functionally equivalent declaration was added. defines as an alias for to ensure parity with C++. In C23, was renamed to and the string literal argument was made optional. Gnulib defines for platforms that do not use C11 and does not require to be included. === === The keyword, added in C++26, is for contract assertions and used to verify internal conditions similar to the assert() macro by ensuring that a condition holds during execution. int f(vector & v) pre (v.size() >= 1 && v[0] > 0) post (r: r == v[0] && r != 1) { // ... contract_assert(v[0] != 1); // ... return v[0]; } ===Citations=== ===Bibliography===

References

No reference rows published for this article.

Cite this article

MLA

"Assert.h." encyclopegia.org, 2026, https://encyclopegia.org/wiki/assert-h. Accessed 24 November 2026.

Chicago

"Assert.h." encyclopegia.org. Accessed November 24, 2026. https://encyclopegia.org/wiki/assert-h.

APA

encyclopegia.org. (2026). Assert.h. Retrieved November 24, 2026, from https://encyclopegia.org/wiki/assert-h

Accessed November 24, 2026 · CC BY-SA 4.0 · citation page · JSON

Related articles

Turkey–United States relations

enwiki · references available

Talpur dynasty

enwiki · references available

Anglo-Persian War

enwiki · references available

Hadrawi

enwiki · references available

Taunusstein

enwiki · references available

Augusta Braxton Baker

enwiki · references available

Ruan Pienaar

enwiki · references available

Brat Fest

enwiki · references available

Pokrovsk Raion

enwiki · references available

Frisby McCullough

enwiki · references available

Giant Food (Landover)

enwiki · references available

Leopold Saverio Vaccaro

enwiki · references available
CC BY-SA 4.0 · share-alike · https://en.wikipedia.org/w/index.php?oldid=1359589742 · 0.5 · snapshot enwiki-001359589742

Cite · JSON · Search

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.