再发一帖,libmysqlclient 奇怪问题,求助大牛,百思不得其解

Jim_sh 2015-04-17 03:08:56
之前帖子
http://bbs.csdn.net/topics/391018240?page=1#post-399111712
我又多番研究,找到一点蛛丝马迹,会不会和“结构体对齐”或者“c++对象内存布局”有点关系,但是我目前所学知识还不能理解这个现象,分隔线上面和下面有啥区别???

各位看看下面代码:


struct test_struct
{
MYSQL fuck_mysql;
int fuck_int;
};

void foo()
{
test_struct ts;
ts.fuck_int = 0;
if (!mysql_init(&ts.fuck_mysql))
{
cout << "mysql_init error. ret:" << string(mysql_error(&ts.fuck_mysql)) << endl;
}
if (!mysql_real_connect(&ts.fuck_mysql,
"192.168.111.120",
"root",
"123",
0,
3306, NULL, 0))
{
cout << "mysql_real_connect error. ret:" << string(mysql_error(&ts.fuck_mysql)) << endl;
}
cout << "ts.fuck_int:" << ts.fuck_int << endl;

cout << "-----------------------------------分隔线-----------------------------------------------" << endl;

int before = 0;
MYSQL connection;
int after = 0;
if (!mysql_init(&connection))
{
cout << "mysql_init error. ret:" << string(mysql_error(&connection)) << endl;
}
if (!mysql_real_connect(&connection,
"192.168.111.120",
"root",
"123",
0,
3306, NULL, 0))
{
cout << "mysql_real_connect error. ret:" << string(mysql_error(&connection)) << endl;
}
cout << "before:" << before << endl;
cout << "after:" << after << endl;

}


得到结果是:
ts.fuck_int:17765728
-----------------------------------分隔线-----------------------------------------------
before:0
after:0

这个地方,fuck_int和after有啥区别呢???
...全文
113 回复 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

65,186

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧