From: Nikanth Karthikesan <knikanth@novell.com>
To: rusty@rustcorp.com.au
Cc: nikanth@gmail.com, linux-kernel@vger.kernel.org
Subject: Strange code in include/linux/cpumask.h
Date: Wed, 25 Mar 2009 10:21:13 +0530 [thread overview]
Message-ID: <200903251021.13811.knikanth@novell.com> (raw)
Hi Rusty
I do not understand this code.
/**
* to_cpumask - convert an NR_CPUS bitmap to a struct cpumask *
* @bitmap: the bitmap
*
* There are a few places where cpumask_var_t isn't appropriate and
* static cpumasks must be used (eg. very early boot), yet we don't
* expose the definition of 'struct cpumask'.
*
* This does the conversion, and can be used as a constant initializer.
*/
#define to_cpumask(bitmap) \
((struct cpumask *)(1 ? (bitmap) \
: (void *)sizeof(__check_is_bitmap(bitmap))))
static inline int __check_is_bitmap(const unsigned long *bitmap)
{
return 1;
}
The conditional operator would always evaluates to true and return bitmap. So
all it seems to does is
#define to_cpumansk(bitmap) (struct cpumask *)(bitmap)
Even If it would return (void *)sizeof(__check_is_bitmap(bitmap)), wouldn't it
be always
(struct cpumask *) (sizeof(1))!?
Is this some magic for type safety?
Thanks
Nikanth
next reply other threads:[~2009-03-25 4:53 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-25 4:51 Nikanth Karthikesan [this message]
2009-03-25 5:11 ` Rusty Russell
2009-03-25 6:44 ` Nikanth Karthikesan
2009-03-25 22:44 ` Rusty Russell
2009-03-26 4:12 ` Nikanth Karthikesan
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=200903251021.13811.knikanth@novell.com \
--to=knikanth@novell.com \
--cc=linux-kernel@vger.kernel.org \
--cc=nikanth@gmail.com \
--cc=rusty@rustcorp.com.au \
/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
Powered by JetHome