#include <stdio.h>
#include <stdlib.h>
struct str{
int t;
char v;
};
union uni{
int t;
char v;
}u;
int g = 15;
void fun(int* xp){
void (*f) (int*) = fun;
struct str s = {1, 'a'};
union uni *up = (union uni *) malloc(sizeof(union uni));
int *ip[2] = {xp, &g};
up->v = s.v + 1;
printf("\n%p\n",&g);
printf("ip = %p, *ip = %p, **ip = %d\n", ip, *ip, **ip);
printf("ip+1 = %p, ip[1] = %p, *ip[1] = %d\n", ip+1, ip[1], *ip[1]);
printf("&s.v = %p, s.v = '%c'\n", &s.v, s.v);
printf("&up->v = %p, up->v = '%c'\n", &up->v, up->v);
printf("&up->t = %p, up->t = '%c'\n", &up->t, up->t);
printf("f = %p\n", f);
if (--(*xp) > 0)
f(xp);
}
int main(){
int x = 2;
fun(&x);
return 0;
}
运行结果
0x100008020
ip = 0x7ffeefbff340, ip = 0x7ffeefbff378, ip = 2
ip+1 = 0x7ffeefbff348, ip[1] = 0x100008020, ip[1] = 15
&s.v = 0x7ffeefbff32c, s.v = ‘a’
&up->v = 0x105b398d0, up->v = ‘b’
&up->t = 0x105b398d0, up->t = ‘b’
f = 0x100003d100x100008020
ip = 0x7ffeefbff2c0, ip = 0x7ffeefbff378, ip = 1
ip+1 = 0x7ffeefbff2c8, ip[1] = 0x100008020, ip[1] = 15
&s.v = 0x7ffeefbff2ac, s.v = ‘a’
&up->v = 0x105835870, up->v = ‘b’
&up->t = 0x105835870, up->t = ‘b’
f = 0x100003d10