not human being~~~
以下所说 也许不是什么新东西,只是今天我才知道
typedef struct {
int min;
char ch;
char ch1;
int min1;
}str;
printf("%x", (unsigned long) ( &( (struct str *)0->;min ) ) )
printf("%x", (unsigned long) ( &( (struct str *)0->;ch) ) )
printf("%x", (unsigned long) ( &( (struct str *)0->;min1 ) ) )
printf("%x", (unsigned long) ( &( (struct str *)0->;ch1) ) )
result:
0
4
5
8
问题:
1 知道typedef struct 类型变量的地址,如何取得该变量的min1域的地址
2 知道typedef struct 类型变量中min1域的地址pmin,如何取得 该变量的地址
一正一反的两个问题
答案:
1 str *p = &(str s)
&(p->;min)
2 str *p
p = (struct str *)( (char *)pmin - (unsigned long)( &( (struct str *)0->;min ) ) )
typedef struct {
int min;
char ch;
char ch1;
int min1;
}str;
printf("%x", (unsigned long) ( &( (struct str *)0->;min ) ) )
printf("%x", (unsigned long) ( &( (struct str *)0->;ch) ) )
printf("%x", (unsigned long) ( &( (struct str *)0->;min1 ) ) )
printf("%x", (unsigned long) ( &( (struct str *)0->;ch1) ) )
result:
0
4
5
8
问题:
1 知道typedef struct 类型变量的地址,如何取得该变量的min1域的地址
2 知道typedef struct 类型变量中min1域的地址pmin,如何取得 该变量的地址
一正一反的两个问题
答案:
1 str *p = &(str s)
&(p->;min)
2 str *p
p = (struct str *)( (char *)pmin - (unsigned long)( &( (struct str *)0->;min ) ) )