[PATCH v3 09/22] common/idpf: refactor size check macro
Soumyadeep Hore
soumyadeep.hore at intel.com
Wed Jun 12 05:52:44 CEST 2024
Instead of using 'divide by 0' to check the struct length,
use the static_assert macro
Signed-off-by: Soumyadeep Hore <soumyadeep.hore at intel.com>
---
drivers/common/idpf/base/virtchnl2.h | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/drivers/common/idpf/base/virtchnl2.h b/drivers/common/idpf/base/virtchnl2.h
index 1f59730297..f8b97f2e06 100644
--- a/drivers/common/idpf/base/virtchnl2.h
+++ b/drivers/common/idpf/base/virtchnl2.h
@@ -41,15 +41,12 @@
/* State Machine error - Command sequence problem */
#define VIRTCHNL2_STATUS_ERR_ESM 201
-/* These macros are used to generate compilation errors if a structure/union
- * is not exactly the correct length. It gives a divide by zero error if the
- * structure/union is not of the correct size, otherwise it creates an enum
- * that is never used.
+/* This macro is used to generate compilation errors if a structure
+ * is not exactly the correct length.
*/
-#define VIRTCHNL2_CHECK_STRUCT_LEN(n, X) enum virtchnl2_static_assert_enum_##X \
- { virtchnl2_static_assert_##X = (n)/((sizeof(struct X) == (n)) ? 1 : 0) }
-#define VIRTCHNL2_CHECK_UNION_LEN(n, X) enum virtchnl2_static_asset_enum_##X \
- { virtchnl2_static_assert_##X = (n)/((sizeof(union X) == (n)) ? 1 : 0) }
+#define VIRTCHNL2_CHECK_STRUCT_LEN(n, X) \
+ static_assert((n) == sizeof(struct X), \
+ "Structure length does not match with the expected value")
/* New major set of opcodes introduced and so leaving room for
* old misc opcodes to be added in future. Also these opcodes may only
--
2.43.0
More information about the dev
mailing list