Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F110088021
D29833.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D29833.diff
View Options
diff --git a/share/man/man3/Makefile b/share/man/man3/Makefile
--- a/share/man/man3/Makefile
+++ b/share/man/man3/Makefile
@@ -72,6 +72,7 @@
arb.3 ARB_RIGHT.3 \
arb.3 ARB_RIGHTIDX.3 \
arb.3 ARB_ROOT.3
+MLINKS+= assert.3 static_assert.3
MLINKS+= ATOMIC_VAR_INIT.3 atomic_compare_exchange_strong.3 \
ATOMIC_VAR_INIT.3 atomic_compare_exchange_strong_explicit.3 \
ATOMIC_VAR_INIT.3 atomic_compare_exchange_weak.3 \
diff --git a/share/man/man3/assert.3 b/share/man/man3/assert.3
--- a/share/man/man3/assert.3
+++ b/share/man/man3/assert.3
@@ -28,15 +28,18 @@
.\" @(#)assert.3 8.1 (Berkeley) 6/9/93
.\" $FreeBSD$
.\"
-.Dd May 31, 2018
+.Dd April 20, 2021
.Dt ASSERT 3
.Os
.Sh NAME
-.Nm assert
+.Nm assert ,
+.Nm static_assert
.Nd expression verification macro
.Sh SYNOPSIS
.In assert.h
.Fn assert expression
+.Fn static_assert expression
+.Fn static_assert expression message
.Sh DESCRIPTION
The
.Fn assert
@@ -81,6 +84,21 @@
macro should only be used for ensuring the developer's expectations
hold true.
It is not appropriate for regular run-time error detection.
+.Pp
+The
+.Fn static_assert
+macro expands to
+.Fn _Static_assert ,
+and, contrarily to
+.Fn assert ,
+makes assertions at compile-time.
+Once the constraint is violated, the compiler produces a diagnostic
+message including the string literal message, if provided.
+The initial form of the
+.Fn _Static_assert
+containing a string literal message was introduced in C11 standard, and
+the other form with no string literal is to be implemented by C2x and
+some compilers may lack its adoption at present.
.Sh EXAMPLES
The assertion:
.Dl "assert(1 == 0);"
@@ -95,14 +113,29 @@
Second, the code will disappear if
.Dv NDEBUG
is defined, changing the semantics of the program.
+.Pp
+The following asserts that the size of the S structure is 16.
+Otherwise, it produces a diagnostic message which points at the
+constraint and includes the provided string literal:
+.Dl "static_assert(sizeof(struct S) == 16, ""size mismatch"");"
+If none is provided, it only points at the constraint.
.Sh SEE ALSO
.Xr abort2 2 ,
.Xr abort 3
.Sh STANDARDS
+.Rs
The
.Fn assert
macro conforms to
.St -isoC-99 .
+.Re
+.Pp
+.Rs
+The
+.Fn static_assert
+macro conforms to
+.St -isoC-2011 .
+.Re
.Sh HISTORY
An
.Nm
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Feb 14, 11:26 AM (21 h, 5 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
16641816
Default Alt Text
D29833.diff (2 KB)
Attached To
Mode
D29833: assert(3): Update with _Static_assert
Attached
Detach File
Event Timeline
Log In to Comment