CTASSERT(9)
π CTASSERT(9) β the compile time assertion macro, bestie π
okay so real talk, you're reading a page from the Kernel Developer's Manual and it's about CTASSERT β a macro that yells at you before your code even runs. we love a preemptive queen π
β¨ NAME β¨
CTASSERT β the compile time assertion macro. that's it, that's the whole vibe check π
πΈ SYNOPSIS πΈ
#include <sys/param.h>
#include <sys/systm.h>
CTASSERT(expression);
like, include both headers, then hit it with the macro. simple. iconic. π¦
π DESCRIPTION π
okay so first things first, and I need you to hear me on this: the CTASSERT() macro is deprecated π β the C11 standard _Static_assert() should be used instead. so like, this one still works, but it's giving "your older cousin who's still cool but please move on."
if you are worried about pre-C11 compilers (compatibility era π), you should include the sys/cdefs.h header to provide compatibility for them. that's the move.
so what does it actually do? the CTASSERT() macro evaluates expression at compile time and causes a compiler error if it is false. no runtime surprises, no "why is my kernel on fire at 3am" energy β the compiler just straight up refuses. periodt β
and that's exactly why it's useful: the CTASSERT() macro is useful for asserting the size or alignment of important data structures and variables during compilation, which would otherwise cause the code to fail at run time. ngl, catching that at build time instead of 3am in production is a whole personality trait π₯π
π§ EXAMPLES π§
say it with me: assert that the size of the uuid structure is 16 bytes. π
CTASSERT(sizeof(struct uuid) == 16);
that's it. that's the whole example. she's brief, she's effective, she ate. π
π SEE ALSO π
KASSERT(9)β the runtime sibling, iykyk π«Ά
π AUTHORS π
This manual page was written by Hiten M. Pandya <hmp@FreeBSD.org>. thank you for your service, legend π«‘β¨
and that's the whole page, bestie! this lil gem is from Debian, dated August 1, 2015, and yes it's still filed under CTASSERT(9) in the manual. go forth and assert your expressions at compile time β or, like, use _Static_assert() because... deprecated ππ π¦β
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- nixpkgs unstable: source
- Copyright (c) 2003 Hiten M. Pandya
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms