Type sanity: add compile time check that integers are of the expected size.
authorKp <kp@valhallalegends.com>
Sun, 1 Jun 2008 04:41:59 +0000 (23:41 -0500)
committerKp <kp@valhallalegends.com>
Mon, 1 Sep 2008 19:48:40 +0000 (14:48 -0500)
The comments in silctypes.h guarantee that certain types are of
particular sizes.  Add compile time checks that will fail if these
guarantees are not met.

lib/silcutil/silctypes.h

index 70bc30165b4a41c530fa8508a90788184c47dd71..b22c7e771d83b1de276eb8edf1aab09ff59aab90 100644 (file)
@@ -634,4 +634,11 @@ do {                                               \
 #endif
 /***/
 
+typedef char __check_size1[sizeof(SilcInt8)   ==       1 ? 1 : -1];
+typedef char __check_size2[sizeof(SilcUInt8)  ==       1 ? 1 : -1];
+typedef char __check_size3[sizeof(SilcInt16)  ==       2 ? 1 : -1];
+typedef char __check_size4[sizeof(SilcUInt16) ==       2 ? 1 : -1];
+typedef char __check_size5[sizeof(SilcInt32)  ==       4 ? 1 : -1];
+typedef char __check_size6[sizeof(SilcUInt32) ==       4 ? 1 : -1];
+
 #endif /* SILCTYPES_H */