Re: Strange variable declarations in Kernel

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,
         The struct here seems to use bitfields.

> 87.  typedef struct _gpt_entry_attributes {
> 88.    u64 required_to_function:1;
> 89.    u64 reserved:47;
> 90.    u64 type_guid_specific:16;
> 91.  } __attribute__ ((packed)) gpt_entry_attributes;
> 

The colon indicates that it is a bitfield and the number after
it is the length of that variable in bits.

AFAIK,bitfields are used to save memory and access (without confusion) 
individual bits of Control Words, maybe of  microprocessors and similar
interfaced devices.In general,they are used when every bit in a word 
sets/unsets an attribute.

Here,the total amount of memory reqd for the struct instance will
be equal to just a single u64 i.e 1+47+16 = 64 bits.
The other way could have been declaring one single u64 which
would have cost us the same amount of mem but then,the 
operations on it would have been cumbersome with the
use of bitwise operators for changing individual bits.
With the use of bitfields,assignment and other operations'
syntaxes are just like that of integer variables.

There are portability problems related to bitfields,but i dont
know what they are exactly.

Regards,
Pranav Peshwe

---------------------------------------------------------------------------
Only that day dawns to which we are awake. 
The Sun is but a morning star.
- Henry David Thoreau (an enlightened american student of the Vedas)



--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux