From patchwork Mon Jun 6 06:12:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ammar Faizi X-Patchwork-Id: 12869985 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D46CC433EF for ; Mon, 6 Jun 2022 06:12:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229806AbiFFGMz (ORCPT ); Mon, 6 Jun 2022 02:12:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229879AbiFFGMp (ORCPT ); Mon, 6 Jun 2022 02:12:45 -0400 Received: from gnuweeb.org (gnuweeb.org [51.81.211.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB0BF1838F for ; Sun, 5 Jun 2022 23:12:43 -0700 (PDT) Received: from integral2.. (unknown [36.73.79.120]) by gnuweeb.org (Postfix) with ESMTPSA id 50A877ED7E; Mon, 6 Jun 2022 06:12:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1654495963; bh=rCu1i8LhhlOrdGzVPKASiSeqaLaUQwOx8jlREhrRbJk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pLFpC+ugkfj7xCmDohna4yz+shAWwP88Sh8PqRMBBzEUliow1ZieJl1mrztrpdnei WhzS2ZX3sHDeD+mSV9mObTxK2bl+CuGLuglvL96WX9Ql4wVxYdAJqWiiMOUUTC5rwn 6+N/M+i6h0QTASsfQJqUkIVC62GXHVZ2FUvFdxJ0OaW5WXy/ap4JxOrg6uexCu3GnG 1KcqxmkXyea9Y0m64syZ0wINC+ZnAkjrIPkurt+STA4OAJYaa1ot4bivpXcZx9podw koD8J9pHid16YibeStzgpj4YRtxdHEb9hoPvovxSciJEMTniMo+S/BE/JGOphLGqeN TLIrPubMzYHIg== From: Ammar Faizi To: Jens Axboe Cc: Ammar Faizi , Pavel Begunkov , "Fernanda Ma'rouf" , Hao Xu , Alviro Iskandar Setiawan , io-uring Mailing List , GNU/Weeb Mailing List Subject: [RFC PATCH v1 3/5] lib: Add `sizeof_field()` macro Date: Mon, 6 Jun 2022 13:12:07 +0700 Message-Id: <20220606061209.335709-4-ammarfaizi2@gnuweeb.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220606061209.335709-1-ammarfaizi2@gnuweeb.org> References: <20220606061209.335709-1-ammarfaizi2@gnuweeb.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org The first use case of this macro is for data structure assertion at compile time. It's like what we do in the io_uring.c in the kernel. Signed-off-by: Ammar Faizi --- src/lib.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lib.h b/src/lib.h index 40e2817..0db7499 100644 --- a/src/lib.h +++ b/src/lib.h @@ -26,6 +26,10 @@ #define BUILD_BUG_ON(EXPR) static_assert(!(EXPR), "!(" #EXPR ") failed") #endif +#ifndef sizeof_field +#define sizeof_field(TYPE, MEMBER) sizeof((((TYPE *)0)->MEMBER)) +#endif + #ifndef offsetof #define offsetof(TYPE, FIELD) ((size_t) &((TYPE *)0)->FIELD) #endif