1874 views|0 replies

2

Posts

0

Resources
The OP
 

Clever use of unions and structures [Copy link]

///////////////////////////////////////////////////Nested definition of structure in union/////////////////////////////////////////////////////////////union _AD_Union_RESULT_{ struct _AD_Struct_RESULT_ { unsigned char AD_RESULT_LO; unsigned char AD_RESULT_HI; }AD_SHORT_BUF; unsigned long AD_RESULT; }AD_LONG_BUF;/ ... This code means: define a union with two variables. The first variable is a variable declared with a structure: AD_SHORT_BUF (including 8*BIT: AD_RESULT_HI + 8*BIT). r]:AD_RESULT_LO); the second variable: 16*BIT[/c olor]AD_RESULT; This structure contains: 8*BIT:AD_RESULT_HIand8*BIT:AD_RESULT_L O, then the compiler will assignRAM addresses to these two registers, for example, it may assign:AD_RESULT_HI:0x32[color=#0000 00];AD_RESULT_LO:0x33[color=#000 000];or AD_RESULT_LO:[/ color]0x32;AD_RESULT_HI0x33; Discover the difference between these two allocations and know the rules of the compiler to allocate addresses; Then the second variable is a 16*BIT: AD_RESULT; the address is the RAM address given by the compiler for the first structure variable;作用就是实现:16*BITAD_RESULT=8*BITAD_RESULT_HI+8*BITAD_RESULT_LO
This post is from 51mcu
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list