首页 > 技术文章 > 复合类型变量其首地址的几种表示方式

skullboyer 2018-01-25 16:02 原文

 

> 测试代码

 1 #include "stdio.h"
 2 
 3 
 4 typedef char           int8_t;
 5 typedef short          int16_t;
 6 typedef int            int32_t;
 7 typedef long long      int64_t;
 8 
 9 typedef unsigned char           uint8_t;
10 typedef unsigned short          uint16_t;
11 typedef unsigned int            uint32_t;
12 typedef unsigned long long      uint64_t;
13 
14 
15 /* ′?′¢×????óê?μ?μ?TDA5238?á1?êy?Y?á11 */
16 typedef struct
17 {
18     uint8_t UniqueID[4];         /* éè±??¨ò?DòáDo? */
19     uint8_t TyrePosition;        /* ??�???�e?? */
20     int16_t Pressure;            /* ??�??1 */
21     int16_t Temperature;         /* ??ì¥???è */
22     int16_t Acceleration;        /* ??á|?ó?ù?è */
23     int16_t Voltage;             /* μ??1?μ */
24     uint8_t CRC8;                /* D£?é?? */
25     uint8_t RESERVED[16];        /* ±£á?×??ú */
26 }TDA5235_RESULT_s;
27 
28 typedef union
29 {
30     TDA5235_RESULT_s tda5235_obj;
31     uint8_t tda5235_buf[sizeof(TDA5235_RESULT_s)];
32 }TDA5235_RESULT_u;
33 
34 TDA5235_RESULT_u tda5235_result;    /* ì¥?1×????á1?êy?Y?á1? */
35 
36 //uint8_t TDA5235_Read_FIFO(uint8_t *pObj)
37 
38 /* 结构体首地址的几种表示 */
39 int main(void)
40 { 
41     printf("This is a struct-address example!\n");
42 
43     printf("&tda5235_result: %#X\n", &tda5235_result);
44     printf("&tda5235_result.tda5235_obj: %#X\n", &tda5235_result.tda5235_obj);
45     printf("&tda5235_result.tda5235_buf: %#X\n", &tda5235_result.tda5235_buf);
46     printf("&tda5235_result.tda5235_obj.UniqueID: %#X\n", &tda5235_result.tda5235_obj.UniqueID);
47 
48     return 0;
49 }

 

> 运行结果

 

推荐阅读