From patchwork Tue Jun 5 09:18:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 10447929 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 07BAE6024A for ; Tue, 5 Jun 2018 09:29:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EFBDA28D40 for ; Tue, 5 Jun 2018 09:29:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E311F28DD7; Tue, 5 Jun 2018 09:29:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 70E7F28D40 for ; Tue, 5 Jun 2018 09:29:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751595AbeFEJ3y (ORCPT ); Tue, 5 Jun 2018 05:29:54 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:38119 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751473AbeFEJ3y (ORCPT ); Tue, 5 Jun 2018 05:29:54 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from yishaih@mellanox.com) with ESMTPS (AES256-SHA encrypted); 5 Jun 2018 12:21:17 +0300 Received: from vnc17.mtl.labs.mlnx (vnc17.mtl.labs.mlnx [10.7.2.17]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id w559J3Xq007517; Tue, 5 Jun 2018 12:19:03 +0300 Received: from vnc17.mtl.labs.mlnx (vnc17.mtl.labs.mlnx [127.0.0.1]) by vnc17.mtl.labs.mlnx (8.13.8/8.13.8) with ESMTP id w559J3vP018695; Tue, 5 Jun 2018 12:19:03 +0300 Received: (from yishaih@localhost) by vnc17.mtl.labs.mlnx (8.13.8/8.13.8/Submit) id w559J3Wi018694; Tue, 5 Jun 2018 12:19:03 +0300 From: Yishai Hadas To: linux-rdma@vger.kernel.org Cc: yishaih@mellanox.com, parav@mellanox.com, majd@mellanox.com Subject: [PATCH rdma-core 1/2] ccan: Add array_size.h file Date: Tue, 5 Jun 2018 12:18:37 +0300 Message-Id: <1528190318-18563-2-git-send-email-yishaih@mellanox.com> X-Mailer: git-send-email 1.8.2.3 In-Reply-To: <1528190318-18563-1-git-send-email-yishaih@mellanox.com> References: <1528190318-18563-1-git-send-email-yishaih@mellanox.com> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Parav Pandit Add array_size.h file for ARRAY_SIZE macro. Signed-off-by: Parav Pandit Signed-off-by: Yishai Hadas --- ccan/CMakeLists.txt | 1 + ccan/array_size.h | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 ccan/array_size.h diff --git a/ccan/CMakeLists.txt b/ccan/CMakeLists.txt index 1793af7..573aa5a 100644 --- a/ccan/CMakeLists.txt +++ b/ccan/CMakeLists.txt @@ -1,4 +1,5 @@ publish_internal_headers(ccan + array_size.h bitmap.h build_assert.h check_type.h diff --git a/ccan/array_size.h b/ccan/array_size.h new file mode 100644 index 0000000..37b200f --- /dev/null +++ b/ccan/array_size.h @@ -0,0 +1,26 @@ +/* CC0 (Public domain) - see LICENSE file for details */ +#ifndef CCAN_ARRAY_SIZE_H +#define CCAN_ARRAY_SIZE_H +#include "config.h" +#include + +/** + * ARRAY_SIZE - get the number of elements in a visible array + * @arr: the array whose size you want. + * + * This does not work on pointers, or arrays declared as [], or + * function parameters. With correct compiler support, such usage + * will cause a build error (see build_assert). + */ +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + _array_size_chk(arr)) + +#if HAVE_BUILTIN_TYPES_COMPATIBLE_P && HAVE_TYPEOF +/* Two gcc extensions. + * &a[0] degrades to a pointer: a different type from an array */ +#define _array_size_chk(arr) \ + BUILD_ASSERT_OR_ZERO(!__builtin_types_compatible_p(typeof(arr), \ + typeof(&(arr)[0]))) +#else +#define _array_size_chk(arr) 0 +#endif +#endif /* CCAN_ALIGNOF_H */