From 9559a9506a2e293b1e4d61a7a93bd9532d2ff92a Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Mon, 3 Feb 2014 14:41:27 +0400 Subject: [PATCH] Static assert for TX queue entry size --- .../include/uavcan/internal/static_assert.hpp | 30 +++++++++++++++++++ .../uavcan/internal/transport/can_io.hpp | 2 ++ 2 files changed, 32 insertions(+) create mode 100644 libuavcan/include/uavcan/internal/static_assert.hpp diff --git a/libuavcan/include/uavcan/internal/static_assert.hpp b/libuavcan/include/uavcan/internal/static_assert.hpp new file mode 100644 index 0000000000..85a707acf2 --- /dev/null +++ b/libuavcan/include/uavcan/internal/static_assert.hpp @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2014 Pavel Kirienko + */ + +#pragma once + +#include + +namespace uavcan +{ + +/** + * Usage: + * StaticAssert::check(); + */ +template +struct StaticAssert +{ +#if __CDT_PARSER__ + static void check() { assert(0); } +#endif +}; + +template <> +struct StaticAssert +{ + static void check() { } +}; + +} diff --git a/libuavcan/include/uavcan/internal/transport/can_io.hpp b/libuavcan/include/uavcan/internal/transport/can_io.hpp index 98efa5431a..a0d6916a88 100644 --- a/libuavcan/include/uavcan/internal/transport/can_io.hpp +++ b/libuavcan/include/uavcan/internal/transport/can_io.hpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -45,6 +46,7 @@ public: , qos(uint8_t(qos)) { assert(qos == VOLATILE || qos == PERSISTENT); + StaticAssert::check(); } bool isExpired(uint64_t monotonic_timestamp) const { return monotonic_timestamp > monotonic_deadline; }