Hello. I have some queries about bit fields :
Let's look at how the MS-DOS operating system stores the date at which a file created or modified?!
The book that I am reading said that storing these numbers as normal integers would waste space of memory. My queries has to do with the memory layout. I have read that the size of a structure is not the sum of the size of its members because of the CPU allignment, is that true? and if it is why we are talking about memory economy? if we create bit fields like here? how we know that we save some memory space?Code:struct file_date { unsigned int day : 5; // 5 is the length of this member in bits unsigned int month: 4; unsigned int year : 7; };
What is the usage of unnamed bit field? What is the "padding" ?
Assuming that we have the following union :
What is the size of this union? It is the biggest member in size but can we know this in advance due to allignment on the structure?Code:union int_date { unsigned short i; struct file_date fd; };