From 7ae84490785b1930bb27ba2307c9a4d593aeb836 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Tue, 6 Sep 2016 09:50:59 -0700 Subject: [PATCH] ircd::util: Add util to output the sizeof() something at compile time. This produces an error which stops compilation, but the result of sizeof() is given in the error message. --- include/ircd/util.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/ircd/util.h b/include/ircd/util.h index 1d33e14fc..66017befb 100644 --- a/include/ircd/util.h +++ b/include/ircd/util.h @@ -324,6 +324,19 @@ UNIT_LITERAL_LD( PB, val * 1000.0L * 1000.0L * 1000.0L * 1000.0L * 1000.0L UNIT_LITERAL_LD( EB, val * 1000.0L * 1000.0L * 1000.0L * 1000.0L * 1000.0L * 1000.0L ) +/* Output the sizeof a structure at compile time. + * This stops the compiler with an error (good) containing the size of the target + * in the message. + * + * example: struct foo {}; IRCD_TEST_SIZEOF(foo) + */ + +template +struct _TEST_SIZEOF_; + +#define IRCD_TEST_SIZEOF(name) \ + ircd::util::_TEST_SIZEOF_ _test_; + } // namespace util } // namespace ircd #endif // __cplusplus