From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NO_DNS_FOR_FROM,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 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 Content-Transfer-Encoding: 8bit List-Id: 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 -- Ammar Faizi