Union
You are not allowed to assign values or other operations to only union variable masterpieces.
Also does not allow initialization of union variables, assignment can only be done in the program.
Small-End Storage:
In bytes, low survivable and high.
Any data in memory is stored in binary (1 or 0) order, each 1 or 0 is called 1 bits, and a byte on X86CPU is 8 bits. For example, a 16-bit (2-byte) short int variable has a value of 1156, then its binary expression is: 00000100 10000100. since the Intel CPU architecture is little Endian (small end storage, parametric machine principle related knowledge), so it is stored in reverse byte, then because it is: 10000100 00000100, this is the fixed-point number 1156 in-memory structure.
Use cases in Linux code: union Judgment size End [1]
#include <stdio.h>static Union {char c[4]; unsigned long l;} endian_test = {{' L ', '? ', '? ', ' B '}}; #define Endi Anness ((char) endian_test.l) void F1 (void) { printf ("Endian:%c\n", ENDIANNESS);} int main () { f1 ();} /*[email protected]:/work/dcc# gcc *.c;./a.outendian:l*/
Reference:
1. http://21cnbao.blog.51cto.com/109393/120108
C Language: Union, size end