public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Richard Knutsson <ricknu-0@student.ltu.se>
To: Jan Engelhardt <jengelh@linux01.gwdg.de>
Cc: Andrew Morton <akpm@osdl.org>,
	Prajakta Gudadhe <pgudadhe@nvidia.com>,
	jeff@garzik.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2.6.18-rc4-mm2] Generic boolean
Date: Thu, 24 Aug 2006 06:06:06 +0200	[thread overview]
Message-ID: <44ED25AE.9030003@student.ltu.se> (raw)
In-Reply-To: <Pine.LNX.4.61.0608231403280.14327@yvahk01.tjqt.qr>

Jan Engelhardt wrote:

>Hi,
>
>
>  
>
>>There has been concern about adding other values then 0 and 1. There has been
>>ideas to do something like:
>>bool b = i & 1 : 0;
>>    
>>
>
>I think you miseed a '?'
>  
>
Yes, thanks...

>bool b = (i & 1) ? : 0;
>  
>
...but I meant: bool b = i ? 1 : 0;

>  
>
>>/*or*/
>>bool b = !!i;
>>
>>but all that is needed is just a casting:
>>
>>bool b = (bool) i;
>>    
>>
>
>No casting needed (in fact, casting is more evil than !!). If bool is a
>  
>
Please inform me why casting is evil (other then risking losing data, by 
cutting the value). But also, _Bool-casting is after all a bit special 
since it does not seem (at least by me) to be able to get a wrong value 
(giving it a value other then 0 but reciving 0).

>bool, then the compiler will (hopefully) ensure that b will only get
>values valid for bools.
>  
>
No, not really. Because _Bool is a byte and not a bit, you can put in a 
value other then 0 or 1 if you cast the pointer (if you insert 256 it 
becomes 0). But after all, there should not be any:
if (b == true)
in the code anyway, so it should be ok.

>Jan Engelhardt
>  
>
/Richard Knutsson

      reply	other threads:[~2006-08-24  3:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-22  1:17 [PATCH] Sgpio support in sata_nv Prajakta Gudadhe
2006-08-22  5:44 ` Andrew Morton
2006-08-22 22:54   ` Generic booleans in -mm (was: Re: [PATCH] Sgpio support in sata_nv) Richard Knutsson
2006-08-22 23:17     ` Andrew Morton
2006-08-23 11:14       ` [PATCH 2.6.18-rc4-mm2] Generic boolean (was: Re: Generic booleans in -mm) Richard Knutsson
2006-08-23 12:06         ` Jan Engelhardt
2006-08-24  4:06           ` Richard Knutsson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=44ED25AE.9030003@student.ltu.se \
    --to=ricknu-0@student.ltu.se \
    --cc=akpm@osdl.org \
    --cc=jeff@garzik.org \
    --cc=jengelh@linux01.gwdg.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pgudadhe@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox