Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp2162118imd; Sun, 28 Oct 2018 04:26:24 -0700 (PDT) X-Google-Smtp-Source: AJdET5cAySjlUs/f0n9m51RjC5H3L5BnfP+da0nqaeEEizhIsSzmBvp2QpJ3/hhoCSRqo748OROy X-Received: by 2002:a17:902:8309:: with SMTP id bd9-v6mr10260796plb.161.1540725984497; Sun, 28 Oct 2018 04:26:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540725984; cv=none; d=google.com; s=arc-20160816; b=caCBIzZAzIsa5o7HXDnUhZYbhnt22HkjC/DRC8z7Xymcpkboo22ZPncgMbBJusTrYN hVgxpNymilhaWk2MntA9wi9y5CvDH/Q80rDS4grkEMaXXnykf+ezsf0misJc/Ks/ogHl Koq0PYj6DbtRgFq4xiP1hTZd7xZuTpzM22S+9L4drpG9Uf6rmmgHnpYd9GKVKPRr5tmH mjCFTZQ6HBgnZci5cX3V82dqGY7uU3499+FkzPFxHB/zvJprCKZZB28YQr/pqwfZ4w0f wI8AZeAbtDRDNVHxKx52dT/Zjg1b9BJhnmcOs0fFuK7zDy8NkfY+J/x6QYEHf8fnho+8 cOFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=URUJOjWx2zMb8INLm3z0n3/dESvN8PI2X6HDtfi34hA=; b=m50cx7tE4KCs5oM+nqUysFKS9vjIPYgSYJ/+xvgZ+e84wO5aPtVH8+Qe+DUvkMf6Rg 9U06wEsSM6w+Nsq2yG1r6D4DH9OxGg8J4DAddcS4D0/loFpJbh9mfGMmmtdODska2rem b1UcGiJqgI5ePFYtQL3zTpbx04KYuSGhaMjq0zfpvv51FRR7ALsHhv9YUkvsmLQwU6PQ xqWkq8s8+FWbndgYsKV48XEcz9kyUQP3um93lUlDYCrxFZCjkcMmsoIhWEkclb5YbgAW pcaTAxCCubb1sVhfAJ8+S70NElujtn4JFDCSUiWuQg4ZtO9peRSmtio4LJ3ouJ9dT2KP 1Sfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=pC8kmSG0; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e11-v6si17201847pgi.139.2018.10.28.04.26.06; Sun, 28 Oct 2018 04:26:24 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=pC8kmSG0; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727387AbeJ1UEn (ORCPT + 99 others); Sun, 28 Oct 2018 16:04:43 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:42129 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726379AbeJ1UEm (ORCPT ); Sun, 28 Oct 2018 16:04:42 -0400 Received: by mail-pg1-f194.google.com with SMTP id i4-v6so2523494pgq.9 for ; Sun, 28 Oct 2018 04:20:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=URUJOjWx2zMb8INLm3z0n3/dESvN8PI2X6HDtfi34hA=; b=pC8kmSG0jf4qmgvy1e8KpRPT4wvM38fUU/wiEPLqevXNUYcRO7ewaLPheiG+c44kJY dJxk99v3xyGHNd4igH4tkRLvJsixCKNuz6fPdvsSg9Vhe8gWNQrihsIJx9ZUFBjX8NBq Tx23BMSnwZwerJgM4BQFCXbv5oe48lH3lAEL4hzCEsIk5V0i8P2+OKal/0R222zk3x2T Xbypx4K4k3vJI1B6+IP1L9aG6Gr+LwKWc9rizRDt9gu8QzX0fvv2un/guqY4jqIG+4jH dc3mwkznVd7q/+v9T7184AITTYltx1PCbgUo5BOYQ5dPN3Ye1TNci0QrUPWOO+mbqX8H NlLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=URUJOjWx2zMb8INLm3z0n3/dESvN8PI2X6HDtfi34hA=; b=jxMa9cATxVi/MIKjk2692CZXzWQQNJs2KtaNL3hHeNl3erIw8wJ1tkGELKOLb3dlrd f5Z53I4cPMzwkSzXKPfLFbv+L0nCC18z3xZjo4yDpspuapU638N+QVB0ZexAQja0qh0r RWohs+lnnSmHdIcApfiApCR1wjwYrC4M/Pxek1apdKrI9Tt10X62hz5Nus8shJqVjB2d WXTvFHLyquO7t+uNW8CPZtERkIaqHs+Ie+OOXtxO2cJuNxA2fyXew8BUDg1Vw4wz3e3L IXoFnF0AGOlnAMg18DM1bFu7TWu4a2dPvwfR6jUbmKHLrgzdV9nAzlQ7k6lUcOMTsVP2 FAPw== X-Gm-Message-State: AGRZ1gK4G//YCWB3CEkWjcktWUZSuKDiI16IOIQbdCaHzPxdTN2zPnxY I2eHsyLsOl75sppN5MFWgl8= X-Received: by 2002:a62:6506:: with SMTP id z6-v6mr10823075pfb.20.1540725620243; Sun, 28 Oct 2018 04:20:20 -0700 (PDT) Received: from himanshu-Vostro-3559 ([103.233.116.134]) by smtp.gmail.com with ESMTPSA id u124-v6sm36137938pgc.0.2018.10.28.04.20.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 28 Oct 2018 04:20:19 -0700 (PDT) Date: Sun, 28 Oct 2018 16:50:12 +0530 From: Himanshu Jha To: Julia Lawall Cc: Sasha Levin , Shayenne da Luz Moura , Greg Kroah-Hartman , Hans de Goede , Michael Thayer , devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, outreachy-kernel@googlegroups.com Subject: Re: [Outreachy kernel] [RESEND PATCH 2/2] staging: vboxvideo: Use unsigned int instead bool Message-ID: <20181028112011.GA5157@himanshu-Vostro-3559> References: <211701e4ae42acd95afb24713314bce5a4c58ecf.1540580493.git.shayenneluzmoura@gmail.com> <20181026204225.GH2015@sasha-vm> <20181028075209.GA1938@himanshu-Vostro-3559> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Oct 28, 2018 at 09:47:15AM +0100, Julia Lawall wrote: > > The "possible alignement issues" in CHECK report is difficult to figure > > out by just doing a glance analysis. :) > > > > Linus also suggested to use bool as the base type i.e., `bool x:1` but > > again sizeof(_Bool) is implementation defined ranging from 1-4 bytes. > > If bool x:1 has the size of bool, then wouldn't int x:1 have the size of > int? But my little experiments suggest that the size is the smallest that > fits the requested bits and alignment chosen by the compiler, regardless of > the type. Yes, correct! And we can't use sizeof on bitfields *directly*, nor reference it using a pointer. It can be applied only when these bitfields are wrapped in a structure. Testing: #include #include struct S { bool a:1; bool b:1; bool c:1; bool d:1; }; int main(void) { printf("%zu\n", sizeof(struct S)); } Output: 1 If I change all bool to unsigned int, output is: *4*. So, conclusion is compiler doesn't squeeze the size less than native size of the datatype i.e., if we changed all members to unsigned int:1, total width = 4 bits padding = 4 bits Therefore, total size should have been = 1 byte! But since sizeof(unsigned int) == 4, it can't be squeezed to less than it. > bool x:1 has the advantage that anything that is not 0 is considered true. Yes, implicit conversion rules for boolean. > So for bool x:1, x = 4 is true, while for int x:1, x = 4 is false. Well, int x:1 can either have 0..1 or -1..0 range due implementation defined behavior as I said in the previous reply. If you really want to consider negative values, then make it explicit using `signed int x:1` which make range guaranteed to be -1..0 Regardless, integer conversion rules will kick in. > But the :1 adds instructions, so at least for only one bool, where little > space is saved, it is probably not worth it. True, we should reply on a promised guideline rather than possibility. -- Himanshu Jha Undergraduate Student Department of Electronics & Communication Guru Tegh Bahadur Institute of Technology