comparison src/sanity.cc @ 109:f05330267c66

Use stdint types.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 06 Oct 2014 12:59:23 +0300
parents a68786b9c74b
children
comparison
equal deleted inserted replaced
108:c91965fc33b6 109:f05330267c66
38 * 38 *
39 * Sanity checks about the sizes and properties of certain types. 39 * Sanity checks about the sizes and properties of certain types.
40 * Useful when porting. 40 * Useful when porting.
41 */ 41 */
42 42
43 #define assert_size(type,size) \ 43 #define assert_size(type,size) \
44 do \ 44 do \
45 { \ 45 { \
46 if (sizeof (type) != size) \ 46 if (sizeof (type) != size) \
47 fatal_error ("sizeof " #type " is %d (should be " #size ")", \ 47 fatal_error ("sizeof " #type " is %d (should be " #size ")", \
48 (int) sizeof (type)); \ 48 (int) sizeof (type)); \
49 } \ 49 } \
50 while (0) 50 while (0)
51 51
52 #define assert_wrap(type,high,low) \ 52 #define assert_wrap(type,high,low) \
53 do \ 53 do \
54 { \ 54 { \
55 type n = high; \ 55 type n = high; \
56 if (++n != low) \ 56 if (++n != low) \
57 fatal_error ("Type " #type " wraps around to %lu (should be " #low ")",\ 57 fatal_error ("Type " #type " wraps around to %lu (should be " #low ")",\
58 (unsigned long) n); \ 58 (unsigned long) n); \
59 } \ 59 } \
60 while (0) 60 while (0)
61
61 62
62 void check_types() 63 void check_types()
63 { 64 {
64 assert_size(u8, 1); 65 assert_size(uint8_t, 1);
65 assert_size(i8, 1); 66 assert_size(int8_t, 1);
66 assert_size(u16, 2); 67 assert_size(uint16_t, 2);
67 assert_size(i16, 2); 68 assert_size(int16_t, 2);
68 assert_size(u32, 4); 69 assert_size(uint32_t, 4);
69 assert_size(i32, 4); 70 assert_size(int32_t, 4);
70 assert_size(struct LineDef, 14); 71 assert_size(struct LineDef, 14);
71 assert_size(struct Sector, 26); 72 assert_size(struct Sector, 26);
72 assert_size(struct SideDef, 30); 73 assert_size(struct SideDef, 30);
73 assert_size(struct Thing, 10); 74 assert_size(struct Thing, 10);
74 assert_size(struct Vertex, 4); 75 assert_size(struct Vertex, 4);
75 assert_wrap(u8, 255, 0); 76 assert_wrap(uint8_t, 255, 0);
76 assert_wrap(i8, 127, -128); 77 assert_wrap(int8_t, 127, -128);
77 assert_wrap(u16, 65535, 0); 78 assert_wrap(uint16_t, 65535, 0);
78 assert_wrap(i16, 32767, -32768); 79 assert_wrap(int16_t, 32767, -32768);
79 assert_wrap(u32, 4294967295u, 0); 80 assert_wrap(uint32_t, 4294967295u, 0);
80 assert_wrap(i32, 2147483647, -2147483648); 81 assert_wrap(int32_t, 2147483647, -2147483648);
81 } 82 }
82 83
83 84
84 /* 85 /*
85 * check_charset 86 * check_charset