c - 铸造一个 void ** return
问题描述
我们都知道不应该将/的void *
返回值强制转换,但是返回的类似函数呢?我有以下功能:malloc
calloc
void **
void **calloc_2d(const size_t ptr_count, const size_t size_buffers, const size_t size_elem)
{
void **array = calloc(ptr_count, sizeof(void *));
for (size_t i=0; i < ptr_count; i++)
array[i] = calloc(size_buffers, size_elem);
return array;
}
我可以这样称呼它:
char **string_array = calloc_2d(5, 32, sizeof(char));
但与calloc
这里的常规不同,Visual Studio 告诉我
警告 C4133 '=':不兼容的类型 - 从 'void **' 到 'char **'
听起来我应该投它,为什么?有没有什么办法可以避免每次调用这个函数时强制转换?
解决方案
推荐阅读
- mongoose - 如何在猫鼬中使用 UpdateMany
- php - 用php去除html代码和空格
- javascript - 如何在云功能中访问 firebase 数据库中的其他数据?
- material-ui - /styles/withStyles defaultTheme 选项,不能设置自定义主题
- ruby-on-rails - Rails one_to_many 关联不起作用
- uml - 如何绘制带有嵌套 if 语句的 UML 图?
- multi-select - Slack 应用程序是否支持消息菜单中的多选下拉菜单?
- c - 套接字的半关闭是否会导致 epoll 停止接收事件?
- keras - 即使添加回调后最好的模型也没有保存
- airflow - 如何自动重新安排气流任务