Consortium in C Language

Source: Internet
Author: User
Many low-end development and network protocol stacks are used for network chip development.

A simple example
We have a 32-bit variable.
We may also need to use a's low 16-bit al
At this time, we can define a union to represent Al.
If 16 needs to be divided again, you can use the Union again in the Union.

Write an example.

1 # Include < Stdio. h >
2
3 Typedef Union
4 {
5 Unsigned Int Ax;
6 Struct Ax
7 {
8 Unsigned Int Al: 16 ;
9 Unsigned Int AH: 16 ;
10 } Sax;
11 } Example;
12
13 Int Main ( Void )
14 {
15 Example;
16 A. Ax =   0 xafafbebe ;
17
18   Int I = A. Sax. Ah;
19 Printf ( " Ax = 0x % x, Ah = 0x % x, Al = 0x % x \ n " , A. Ax, A. Sax. Ah, A. Sax. al );
20
21   Return   0 ;
22 }
23
24

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.