Skip to contentSkip to conversation

0 bit shift

DISCUSSION Tobin C. Harding 2 participants 3 messages Mar 29, 2017 – Mar 30, 2017

lore
Share & tools
lore
#0 lore raw

What is the reason for the zero bit shift in this code please?

#define SDIO_STATE_PRESENT (1<<0) /* present in sysfs */

file: include/linux/mmc/sdio_func.h

thanks,
Tobin.

#1 lore raw
Quoted 5 lines · Tobin C. Harding

What is the reason for the zero bit shift in this code please?

#define SDIO_STATE_PRESENT (1<<0) /* present in sysfs */

file: include/linux/mmc/sdio_func.h

Most likely, to indicate that it's a bitmask in the 'unsigned int state' in the line above, rather than an integer.

See the other 2 uses of the flag in-tree:

[/usr/src/linux-next] git grep SDIO_STATE_PRESENT
include/linux/mmc/sdio_func.h:#define SDIO_STATE_PRESENT (1<<0) /* present in sysfs */
include/linux/mmc/sdio_func.h:#define sdio_func_present(f) ((f)->state & SDIO_STATE_PRESENT)
include/linux/mmc/sdio_func.h:#define sdio_func_set_present(f) ((f)->state |= SDIO_STATE_PRESENT)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 484 bytes
Desc: not available
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20170329/afc9f5c4/attachment.bin

#2 lore raw
Quoted 10 lines · valdis.kletnieks at vt.edu
Quoted 5 lines · Tobin C. Harding

What is the reason for the zero bit shift in this code please?

#define SDIO_STATE_PRESENT (1<<0) /* present in sysfs */

file: include/linux/mmc/sdio_func.h

Most likely, to indicate that it's a bitmask in the 'unsigned int state' in the line above, rather than an integer.

Quoted 7 lines

See the other 2 uses of the flag in-tree:

[/usr/src/linux-next] git grep SDIO_STATE_PRESENT
include/linux/mmc/sdio_func.h:#define SDIO_STATE_PRESENT (1<<0) /* present in sysfs */
include/linux/mmc/sdio_func.h:#define sdio_func_present(f) ((f)->state & SDIO_STATE_PRESENT)
include/linux/mmc/sdio_func.h:#define sdio_func_set_present(f) ((f)->state |= SDIO_STATE_PRESENT)

Awesome, thanks.