From: Domen Puncer <domen@coderock.org>
To: kernel-janitors@vger.kernel.org
Subject: Re: [KJ] [PATCH] add new macro BIT_S to include/linux/kernel.h
Date: Thu, 25 Aug 2005 08:46:34 +0000 [thread overview]
Message-ID: <20050825084634.GA2276@homer.coderock.org> (raw)
In-Reply-To: <42FDD89B.1010106@gmx.net>
[-- Attachment #1: Type: text/plain, Size: 978 bytes --]
On 14/08/05 01:11 +0200, Michael Veeck wrote:
> Alexey Dobriyan wrote:
> >On Sat, Aug 13, 2005 at 01:25:15PM +0200, Michael Veeck wrote:
> >
> >>adds a new macro for doing a bitshift. right now every subsystem defines
> >>its own macro (which all look the same) but this one also does overflow
> >>checking
> >
> >
> >Checking?
> >
> >$ cat -n test.c
> > 1 #define BIT(x) (1ULL << (x))
> > 2 #define BITS(x) (1ULL << ((x) % 64))
> > 3
> > 4 int main(void)
> > 5 {
> > 6 BIT(65);
> > 7 BITS(65);
> > 8 return 0;
> > 9 }
> >$ gcc -o test test.c
> >test.c: In function `main':
> >test.c:6: warning: left shift count >= width of type
> > <=== ???
> >
>
> okay, good point, but does that work even when the parameter of BIT isnt
> known at compile time?
How about something like:
#define BITS(x) (1ULL << (__builtin_constant_p(x) ? (x) : (x) % 64)
Or maybe a WARN_ON would be nice, since (x >= 64) probably means there's
a bug.
Domen
[-- Attachment #2: Type: text/plain, Size: 168 bytes --]
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors
next prev parent reply other threads:[~2005-08-25 8:46 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-08-13 11:25 [KJ] [PATCH] add new macro BIT_S to include/linux/kernel.h Michael Veeck
2005-08-13 20:26 ` Alexey Dobriyan
2005-08-13 23:11 ` Michael Veeck
2005-08-25 8:46 ` Domen Puncer [this message]
2005-08-25 19:37 ` Michael Veeck
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=20050825084634.GA2276@homer.coderock.org \
--to=domen@coderock.org \
--cc=kernel-janitors@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.