下面的代码中有什么错误,应该如何更正
What is the error in the code below and how should it be corrected?
下面代码中的错误是什么?应该如何更正?
my_struct_t *bar;
/* ... do stuff, including setting bar to point to a defined my_struct_t object ... */
memset(bar, 0, sizeof(bar));
memset
的最后一个参数不对。
sizeof(bar)
是指针的大小。
你需要一个物体的大小。使用sizeof(*bar)
。
memset(bar, 0, sizeof(*bar));
相关文章:
- 警告处理为错误这里有什么问题
- "error: no matching function for call to"构造函数错误
- boost::进程间消息队列引发错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- QT在错误的班级中寻找空位
- vector.resize()中的分配错误
- 如何'Invalid conversion'和'no match for operator'更正这些 c++ 错误
- 在linux上使用g++输出错误,在windows上更正
- 更正错误
- 数据包丢失 (UDP) 的错误更正代码
- 如何检测浮点表示错误..99999.. 或 ..00000.. 并在C++中更正它们
- 如何更正类型对象错误
- 如何更正此分配错误
- 如何更正运行时错误变量周围的堆栈已损坏
- 检测并更正导致运行时错误的代码
- 更正此错误:GetLastError 0x13d
- 如何使用 __attribute__((__packed__)) 结构的成员更正有关 g++ 引用参数的错误?
- 下面的代码中有什么错误,应该如何更正
- 如何更正程序中检测到的***glibc错误