* Janitor-Question: use __set_bit instead of |=
@ 2011-05-30 21:23 Peter Hüwe
2011-05-31 4:49 ` Greg KH
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Peter Hüwe @ 2011-05-30 21:23 UTC (permalink / raw)
To: kernel-janitors
Hi Janitors, staging-list
what is your opinion on using set_bit instead of using |= to set a bit?
Is it worth the effort to convert existing |= to set_bit?
__set_bit
pro:
- often implemented in optimized assembly (e.g. for x86)
- intention might be clearer
- less error prone
- "they are the only portable way to set a specific bit"
according to Robert Love's Linux Kernel Development third edition, p.183
cons:
uses unsigned longs
|pro:
- standard C
- let's the compiler decide
- no warnings on chars, shorts, ints
Thanks,
Peter
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: Janitor-Question: use __set_bit instead of |=
2011-05-30 21:23 Janitor-Question: use __set_bit instead of |= Peter Hüwe
@ 2011-05-31 4:49 ` Greg KH
2011-05-31 7:11 ` walter harms
2011-05-31 9:05 ` Jiri Slaby
2 siblings, 0 replies; 4+ messages in thread
From: Greg KH @ 2011-05-31 4:49 UTC (permalink / raw)
To: kernel-janitors
On Mon, May 30, 2011 at 11:23:40PM +0200, Peter Hüwe wrote:
> Hi Janitors, staging-list
>
> what is your opinion on using set_bit instead of using |= to set a bit?
> Is it worth the effort to convert existing |= to set_bit?
I doubt converting existing stuff is needed, but any future stuff is
always nice to use set_bit() for the reasons you suggest.
thanks,
greg k-h
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Janitor-Question: use __set_bit instead of |=
2011-05-30 21:23 Janitor-Question: use __set_bit instead of |= Peter Hüwe
2011-05-31 4:49 ` Greg KH
@ 2011-05-31 7:11 ` walter harms
2011-05-31 9:05 ` Jiri Slaby
2 siblings, 0 replies; 4+ messages in thread
From: walter harms @ 2011-05-31 7:11 UTC (permalink / raw)
To: kernel-janitors
Am 30.05.2011 23:23, schrieb Peter Hüwe:
> Hi Janitors, staging-list
>
> what is your opinion on using set_bit instead of using |= to set a bit?
> Is it worth the effort to convert existing |= to set_bit?
>
> __set_bit
> pro:
> - often implemented in optimized assembly (e.g. for x86)
> - intention might be clearer
> - less error prone
> - "they are the only portable way to set a specific bit"
> according to Robert Love's Linux Kernel Development third edition, p.183
>
> cons:
> uses unsigned longs
>
>
> |> pro:
> - standard C
> - let's the compiler decide
> - no warnings on chars, shorts, ints
>
>
Personaly i do not like it, but to be fair
|= must not be obvious but it depends on the situation.
It is std C and the compiler should handle it.
re,
wh
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Janitor-Question: use __set_bit instead of |=
2011-05-30 21:23 Janitor-Question: use __set_bit instead of |= Peter Hüwe
2011-05-31 4:49 ` Greg KH
2011-05-31 7:11 ` walter harms
@ 2011-05-31 9:05 ` Jiri Slaby
2 siblings, 0 replies; 4+ messages in thread
From: Jiri Slaby @ 2011-05-31 9:05 UTC (permalink / raw)
To: kernel-janitors
On 05/30/2011 11:23 PM, Peter Hüwe wrote:
> Hi Janitors, staging-list
>
> what is your opinion on using set_bit instead of using |= to set a bit?
> Is it worth the effort to convert existing |= to set_bit?
>
> __set_bit
> pro:
> - often implemented in optimized assembly (e.g. for x86)
> - intention might be clearer
> - less error prone
> - "they are the only portable way to set a specific bit"
> according to Robert Love's Linux Kernel Development third edition, p.183
>
> cons:
> uses unsigned longs
Note that you need to define a different set of macros.
E.g. if you have for |=:
#define FLAG1 0x01
#define FLAG2 0x02
#define FLAG3 0x40
for set_bit you need:
#define FLAG1 0
#define FLAG2 1
#define FLAG3 6
Also with set_bit you can set only one bit at a time which might make
the code longer and unreadable. For examples, see input layer.
> |> pro:
> - standard C
> - let's the compiler decide
> - no warnings on chars, shorts, ints
regards,
--
js
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-05-31 9:05 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-30 21:23 Janitor-Question: use __set_bit instead of |= Peter Hüwe
2011-05-31 4:49 ` Greg KH
2011-05-31 7:11 ` walter harms
2011-05-31 9:05 ` Jiri Slaby
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox