Re: git: d1f1402dff63 - main - libnetbsd: import `__CTASSERT(..)` macros

From: Enji Cooper (yaneurabeya) <yaneurabeya_at_gmail.com>
Date: Sat, 21 Feb 2026 17:53:14 UTC
> On Feb 21, 2026, at 8:04 AM, John Baldwin <jhb@freebsd.org> wrote:
> 
> On 2/20/26 17:48, Enji Cooper wrote:
>> The branch main has been updated by ngie:
>> URL: https://cgit.FreeBSD.org/src/commit/?id=d1f1402dff63dd163d4ba4ac65f7f2ffd00c5e08
>> commit d1f1402dff63dd163d4ba4ac65f7f2ffd00c5e08
>> Author:     Enji Cooper <ngie@FreeBSD.org>
>> AuthorDate: 2026-02-20 20:24:46 +0000
>> Commit:     Enji Cooper <ngie@FreeBSD.org>
>> CommitDate: 2026-02-20 22:45:06 +0000
>>     libnetbsd: import `__CTASSERT(..)` macros
>>          These compile-time assert macros are similar to `Static_assert` on FreeBSD.
>>          These macros are in use in newer versions of `contrib/netbsd-tests`.
> 
> FYI, _Static_assert is not a FreeBSD-ism, it's part of C11.  Our old CTASSERT is
> a FreeBSD-ism that this extends, but really, these should be implemented in
> terms of _Static_assert when possible.  Something like:
> 
> #if is_c11
> #define __CTASSERT(x)  __Static_assert(x)
> #else
> /* all the rest */
> #endif
> 
> If __CTASSERT0 is used directly anywhere, you could emulate it via something like
> 
> #define __CTASSERT0(x, y, z)  __Static_assert(x, __STRING(y) "_" __STRING(z))
> 
> (Note that we build all of userspace as C17 by default in 15.0 and later.)


Hi jhb@!

Excellent points. Incorporating our macros/adaptations can cause grief sometimes and I don’t want to porting more code than necessary, so I have incorporated these macros (and a few others) wholesale from NetBSD (I got these from [1]).

-Enji

1.  https://github.com/NetBSD/src/blob/c26cc77b3a0b26b95a2df2e0154e2b2f7292ab20/sys/sys/cdefs.h#L168-L182