From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 0A4934414E; Tue, 4 Jun 2024 10:49:54 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C23524357B; Tue, 4 Jun 2024 10:48:58 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.21]) by mails.dpdk.org (Postfix) with ESMTP id 6EA0F43567 for ; Tue, 4 Jun 2024 10:48:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1717490935; x=1749026935; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hOAa79XC8Y54nM7gVYV7sqTdyfboU+vHuWcy/v+Fnec=; b=Sd3X/yj9MxLDHaYM3o3luSN8ZATCiHazoA8n5Q0Xl5IeoZE4h7CAc7md xUi14bBWzyDx2a6wk9sP2owvdTYxG4Oohy0UGbSOIWTqz3mtdGczurm3e tkW0C11LDZlf/mmR1g35h91eMMvvw1HUNcbmn0sXloIvypaD1ZqzMsB7v F1pL9snpSxXh4jzu51A/otsiToDu3RgzKN4QhIVKCzkGzg1zCcCJJqxIe 3Mb2QIUzOxHZrfbUa6jYVyqGR88dVPzRF8lOzDyMfAglsUPQhu/FL3n04 NXDzpPfOrVWi8e5CVy1rhXv4zcAH7g90q9ge3vx8P9RoqBwcVMyD3s2Bj w==; X-CSE-ConnectionGUID: jSVERnnPSveC02AU8NJ0qg== X-CSE-MsgGUID: OqvImcW/RUSgZtLnx7JqNQ== X-IronPort-AV: E=McAfee;i="6600,9927,11092"; a="13971704" X-IronPort-AV: E=Sophos;i="6.08,213,1712646000"; d="scan'208";a="13971704" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa113.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Jun 2024 01:48:54 -0700 X-CSE-ConnectionGUID: TwYbfJatT0KBLrmekx8iNA== X-CSE-MsgGUID: JnEw0ympQli7tnDULBXqRA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,213,1712646000"; d="scan'208";a="42268665" Received: from unknown (HELO npf-hyd-clx-03..) ([10.145.170.182]) by orviesa004.jf.intel.com with ESMTP; 04 Jun 2024 01:48:53 -0700 From: Soumyadeep Hore To: bruce.richardson@intel.com, anatoly.burakov@intel.com Cc: dev@dpdk.org Subject: [PATCH v2 09/21] common/idpf: refactor size check macro Date: Tue, 4 Jun 2024 08:05:59 +0000 Message-ID: <20240604080611.2197835-10-soumyadeep.hore@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240604080611.2197835-1-soumyadeep.hore@intel.com> References: <20240528072839.867100-1-soumyadeep.hore@intel.com> <20240604080611.2197835-1-soumyadeep.hore@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Instead of using 'divide by 0' to check the struct length, use the static_assert macro Signed-off-by: Soumyadeep Hore --- 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