linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* boolean result from a test for a bit
@ 2012-01-27 20:29 Allan, Bruce W
  2012-02-18  1:47 ` Phil Sutter
  0 siblings, 1 reply; 2+ messages in thread
From: Allan, Bruce W @ 2012-01-27 20:29 UTC (permalink / raw)
  To: linux-c-programming@vger.kernel.org,
	kernel-janitors@vger.kernel.org

For a simple boolean test of whether, for example, bit 5 is set in the variable 'flags', which of the following methods is preferred over the other?

bool result = (flags & (1 << 5)) ? true : false;

or

bool result = !!(flags & (1 << 5));

I've seen examples of both in the Linux kernel.

Thanks,
Bruce.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-02-18  1:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-27 20:29 boolean result from a test for a bit Allan, Bruce W
2012-02-18  1:47 ` Phil Sutter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).