| #ifndef MACROS_H |
| |
| #define check_size(_t, _size) assert(sizeof(_t) == (_size)) |
| |
| #define check_align(_t, _align) assert(__alignof__(_t) == (_align)) |
| |
| #define check_align_lv(_t, _align) assert(__alignof__(_t) == (_align) \ |
| && (((unsigned long)&(_t)) & ((_align) - 1) ) == 0) |
| |
| #define check_basic_struct_size_and_align(_type, _size, _align) { \ |
| struct _str { _type dummy; } _t; \ |
| check_size(_t, _size); \ |
| check_align_lv(_t, _align); \ |
| } |
| |
| #define check_array_size_and_align(_type, _size, _align) { \ |
| _type _a[1]; _type _b[2]; _type _c[16]; \ |
| struct _str { _type _a[1]; } _s; \ |
| check_align_lv(_a[0], _align); \ |
| check_size(_a, _size); \ |
| check_size(_b, (_size*2)); \ |
| check_size(_c, (_size*16)); \ |
| check_size(_s, _size); \ |
| check_align_lv(_s._a[0], _align); \ |
| } |
| |
| #define check_basic_union_size_and_align(_type, _size, _align) { \ |
| union _union { _type dummy; } _u; \ |
| check_size(_u, _size); \ |
| check_align_lv(_u, _align); \ |
| } |
| |
| #define run_signed_tests2(_function, _arg1, _arg2) \ |
| _function(_arg1, _arg2); \ |
| _function(signed _arg1, _arg2); \ |
| _function(unsigned _arg1, _arg2); |
| |
| #define run_signed_tests3(_function, _arg1, _arg2, _arg3) \ |
| _function(_arg1, _arg2, _arg3); \ |
| _function(signed _arg1, _arg2, _arg3); \ |
| _function(unsigned _arg1, _arg2, _arg3); |
| |
| /* Check size of a struct and a union of three types. */ |
| |
| #define check_struct_and_union3(type1, type2, type3, struct_size, align_size) \ |
| { \ |
| struct _str { type1 t1; type2 t2; type3 t3; } _t; \ |
| union _uni { type1 t1; type2 t2; type3 t3; } _u; \ |
| check_size(_t, struct_size); \ |
| check_size(_u, align_size); \ |
| } |
| |
| #endif // MACROS_H |