os: osdep: add macro for compile-time type size assert

usage:

   __size_assert(typename, size);

if the type's size (calculated by sizeof) doesn't match the asserted size,
an illegal dummy type will be constructed, thus compilation fails.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
Enrico Weigelt, metux IT consult
2025-07-19 02:19:40 +02:00
committed by Enrico Weigelt
parent b1edd361a0
commit f0cc20eb68

View File

@@ -222,4 +222,10 @@ Ones(unsigned long mask)
#define LIMITCLIENTS 256 /* Must be a power of 2 and <= MAXCLIENTS */
/* static assert for protocol structure sizes */
#ifndef __size_assert
#define __size_assert(what, howmuch) \
typedef char what##_size_wrong_[( !!(sizeof(what) == howmuch) )*2-1 ]
#endif
#endif /* _OSDEP_H_ */