这是来自 gdb:
22 database->size = size;
(gdb) n
23 return database;
(gdb) p size
$6 = 1401
(gdb) p database->size
$7 = 3086862424
(gdb) p &size
$8 = (unsigned int *) 0xbffff050
(gdb) p &database->size
$9 = (unsigned int *) 0xb7fc6ff8
这是来自代码:
typedef struct _DATABASE {
RESULT* res;
unsigned int size;
} DATABASE;
....
....
DATABASE* alloc_database(unsigned int size, DATABASE* database)
{
database = (DATABASE*) malloc (sizeof(DATABASE));
if (!database) return NULL;
database->res = (RESULT*) malloc (sizeof(RESULT) * size);
if (!database->res) {
free_database(database);
return NULL;
}
memset(database->res, 0, sizeof(RESULT) * size);
database->size = size;
return database;
}
您可以看到 database->size 和 size 都来自 (unsigned int) 类型,在代码和 gdb 中,但由于某种原因,赋值后的值不同。
有谁知道这是什么原因?