C Language: Union, size end

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.