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 ECD0C424D8; Wed, 12 Jun 2024 06:37:37 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E826E40E1E; Wed, 12 Jun 2024 06:36:56 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) by mails.dpdk.org (Postfix) with ESMTP id 1C1C940E03 for ; Wed, 12 Jun 2024 06:36:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1718167013; x=1749703013; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hOAa79XC8Y54nM7gVYV7sqTdyfboU+vHuWcy/v+Fnec=; b=YxYV/Z2+H0wfSBhy03/X8DHF12VT5PxUDmqEniwVHm+XiDWlQBT6U4FA pppFGwGYxb7ufXEn5OloGAkgLEobP2nRdY3JINH7XtjZ5HlGncK++/4Ql +6MmT0FtqzyASmc2YBHzl8bnZX+sm/UG3sQr5z5OS5DpRY/3jxPts5Dc2 F//Y7EWs+rFBM5FtaWX/gH5I8N/cCSAMCEZJGAJ+FvXq80YgWk9U0VJHW a7L1dfptimhgnaIovVVF91QLoKX0sVQN3oAYfvubkhtyqOcDDlkYNnDqL RW8nTV5S/rbJuSVjoDyUziG8GkaXzLZgX4eBljozkvXNEgh6osTeLfKnZ Q==; X-CSE-ConnectionGUID: HDCtfId+TCqo5+3eqp7tig== X-CSE-MsgGUID: HyRLSA+xRTa6pyQbSfRY5w== X-IronPort-AV: E=McAfee;i="6600,9927,11100"; a="18742190" X-IronPort-AV: E=Sophos;i="6.08,232,1712646000"; d="scan'208";a="18742190" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jun 2024 21:36:53 -0700 X-CSE-ConnectionGUID: 2YUvMqNwTBielLKNuvmV0Q== X-CSE-MsgGUID: iFhqYVTuTX6urZ8rHWRH5Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,232,1712646000"; d="scan'208";a="40281938" Received: from unknown (HELO npf-hyd-clx-03..) ([10.145.170.182]) by orviesa008.jf.intel.com with ESMTP; 11 Jun 2024 21:36:51 -0700 From: Soumyadeep Hore To: bruce.richardson@intel.com, anatoly.burakov@intel.com Cc: dev@dpdk.org Subject: [PATCH v3 09/22] common/idpf: refactor size check macro Date: Wed, 12 Jun 2024 03:52:44 +0000 Message-ID: <20240612035257.2245824-10-soumyadeep.hore@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240612035257.2245824-1-soumyadeep.hore@intel.com> References: <20240604080611.2197835-1-soumyadeep.hore@intel.com> <20240612035257.2245824-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