一个结构体参数的疑问

小班得瑞 小班得瑞 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我现在有一个结构体

typedef struct
{
size_t *p;
size_t buf[2];
}xxMatStep;

typedef struct
{
int rows;
int cols;

xxMatStep step1;
}XxMat;

static void xxMatStep_Construct_Without_Param( xxMatStep *step1 )
{
step1->p = step1->buf;
step1->p[0] = step1->p[1];
}

static void xxMat_Construct_Without_Param( xxMat *mat )
{
mat->rows = 0;
mat->cols = 0;

xxMatStep_Construct_Without_Param( &mat->step1 );
}

static XxMat xxMat2( int rows, int cols, int step )
{
XxMat m;

xxMat_Construct_Without_Param(&m);
m.rows = rows;
m.cols = cols;
m.step1.p[0] = step;
m.step1.p[1] = 1;

return m;
}

我现在调用xxMat2接口构造一个XxMat结构,发生了一些奇怪的事情,代码如下

XxMat cur_mat = xxMat2( 1280, 720, 1280 );

static void xxMat_DownSample( XxMat *src, XxMat *dst )
{
int sstep = src->step1.p[0];
int dstep = dst->step1.p[0];

//...
}

调用xxMat2后,调试查看cur_mat的成员,step1.p[0],step1.p[1]都是正常的数值,然后我调用xxMat_DownSample(&cur_mat, &dst_mat)出了问题,下断点进入到xxMat_DownSample里,发现sstep即cur_mat的成员step1.p[0]的数值变乱了,VS2010 Debug模式下,sstep数值很大,是3435973836。
请问这是哪里出了问题吗?
...全文

相关推荐

评论 3
收藏 已收藏
分享
返回顶部
小班得瑞
C语言 70,040 成员 243,237 内容