what is aligned and unaligned data in c and what's the use of it.
what is aligned and unaligned data in c and what's the use of it.
The compiler will align variables depending on architecture requirements, or just to improve performance. For a code illustration, run the following:
If you your machine uses 4 byte integers (like most machines), then you might expect the structure to be a size of 5 in the above code. Chances are that if you compile and run that, you will get 8 bytes as the result. Why? Because the compiler aligns the integer on 4 byte boundaries, so there are 3 unused bytes between the character and the integer.Code:#include <stdio.h> struct s { char c; int i; }; int main(void) { printf("size: %u\n", sizeof(struct s)); return 0; }
bit∙hub [bit-huhb] n. A source and destination for information.