AP_Common: add template to check structure size
This has the advantage of telling you what the sizes are In file included from ../../libraries/AC_AttitudeControl/AC_PosControl.h:3: ../../libraries/AP_Common/AP_Common.h:103:3: fatal error: static_assert failed "wrong size" static_assert(s == t, "wrong size"); ^ ~~~~~~ ../../libraries/AP_Common/AP_Common.h:147:52: note: in instantiation of template class 'assert_structure_size<12, 11>' requested here assert_structure_size<sizeof(struct Location), 11> _assert_location_size;
This commit is contained in:
parent
99120cddf9
commit
4dc157951b
@ -100,6 +100,20 @@
|
||||
// @}
|
||||
|
||||
|
||||
// assert_storage_size template: assert that the memory used to store an
|
||||
// item is of a specific size.
|
||||
// example invocation:
|
||||
// assert_storage_size<class Location, 16> _assert_storage_size_Location;
|
||||
// templates are used for this because the compiler's output will
|
||||
// usually contain details of the template instantiation so you can
|
||||
// see how the actual size differs from the expected size.
|
||||
template<typename s, int s_size, int t> struct _assert_storage_size {
|
||||
static_assert(s_size == t, "wrong size");
|
||||
};
|
||||
template<typename s, int t> struct assert_storage_size {
|
||||
_assert_storage_size<s, sizeof(s), t> _member;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @name Types
|
||||
///
|
||||
|
Loading…
Reference in New Issue
Block a user