- 论坛徽章:
- 0
|
能不能帮我看看这段code的运行结果为什么会是这样的:
=============================================
#include <stdlib.h>
#include <stdio.h>
typedef unsigned char U8;
typedef struct
{
U8 value1;
U8 value2;
U8 value3;
U8 value4;
}header;
typedef struct
{
int ab;
char cd;
unsigned char ef;
unsigned char *num;
char gg;
char ff;
int cc;
}Ind;
static void Handle( const Ind *dataInd )
{
header Header;
const U8 *pos = dataInd->num;
printf("num1:%x pos:%x\n",*(dataInd->num), *pos);
Header.value1 = *pos++;
printf("value1 %x pos %x\n",Header.value1, *pos);
Header.value2 = *pos++;
printf("value2 %x pos %x\n", Header.value2 , *pos);
Header.value3 = *pos++;
printf("value3 %x pos %x\n",Header.value3, *pos);
Header.value4 = *pos++;
printf("value4 %x pos %x\n",Header.value4, *pos);
printf("num2 %x\n",*(dataInd->num));
}
int main(void)
{
Ind a;
U8 *vl;
vl = a.num;
*vl=0x01;
Handle(&a);
return 1;
}
==========================================================
bash$./a.out
num1:1 pos:1
value1 1 pos f6
value2 f6 pos ff
value3 ff pos bf
value4 bf pos 33
num2 1
===========================================
pos 后面的值"f6, ff, bf, 33"是怎么得来的?
num的值为什么没变呢? |
|