parent
86fb9a6cf9
commit
9c8833308c
|
@ -3,11 +3,18 @@
|
|||
|
||||
typedef struct {
|
||||
long long id;
|
||||
char *name;
|
||||
char *desc;
|
||||
char name[30];
|
||||
char desc[400];
|
||||
int age;
|
||||
} Person;
|
||||
|
||||
typedef struct {
|
||||
long long id;
|
||||
char *title;
|
||||
char *desc;
|
||||
int version;
|
||||
} SmallObj;
|
||||
|
||||
void test () {
|
||||
static int num = 0;
|
||||
num++;
|
||||
|
@ -30,18 +37,22 @@ int main(int argc, char **argv) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
SmallObj o;
|
||||
SmallObj *r = (SmallObj *) malloc(sizeof(SmallObj));
|
||||
|
||||
// test();
|
||||
// test();
|
||||
// test2();
|
||||
// test2();
|
||||
/**
|
||||
* TODO: 看起来操作系统决定 malloc 申请的内存在哪里
|
||||
* Output on linux64 compiled by clang
|
||||
* addr of p: 0x5619048df2d0, addr of q: 0x7fb51f2e19e0
|
||||
* addr of p: 0x7ffc94fcaf58, addr of q: 0x565297e022a0, addr of o: 0x7ffc94fcaf38, addr of r: 0x565297e02470
|
||||
* Output on win64 compiled by MinGW64 gcc
|
||||
* addr of p: 000000B0591FFB20, addr of q: 000000B0591FFB00
|
||||
*/
|
||||
printf("addr of p: %p, addr of q: %p\n", p, *q);
|
||||
printf("addr of p: %p, addr of q: %p, addr of o: %p, addr of r: %p\n",
|
||||
&p, q, &o, r);
|
||||
free(q);
|
||||
free(r);
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue