]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
Add the new compile-time assertion macro CTASSERT_EQUAL().
authorbz <bz@FreeBSD.org>
Sun, 1 Mar 2009 09:35:41 +0000 (09:35 +0000)
committerbz <bz@FreeBSD.org>
Sun, 1 Mar 2009 09:35:41 +0000 (09:35 +0000)
commit1e29cb8e989182b94c8c02afa8d424cc7c2d5f46
tree066a6ca794959afe7fec3e11bb73251e1f9ed6c3
parent3ca562853b0699e99081db9aa90c0f1b9cbd1cbb
Add the new compile-time assertion macro CTASSERT_EQUAL().
It takes a positive integer constant (the expected value) and
another positive integer, usually compile-time evaluated,
e.g. CTASSERT_EQUAL(FOO_EXPECTED_SIZE, sizeof (struct foo));

While the classic CTASSERT() gives:
 error: size of array '__assert60' is negative
this gives you:
 In function '__ctassert_equal_at_line_60':
 warning: '__expected_42_but_got[464ul]' is used uninitialized in this function
and you can directly see the difference in the expected and the
real value.

CTASSERT_EQUAL() needs special compile time options to trigger
thus keep it locally to this header. If it proves to be of general
interest it can be moved to systm.h.

Submitted by: jmallett
Reviewed by: sam, warner, rwatson, jmallett (earlier versions)
sys/sys/vimage.h