如果我编译下面的代码,我会收到这样的警告:
警告:内置函数 memset 的隐式声明不兼容 [默认启用]
void transform(int **a, int m, int n)
{
int *row = malloc(m*sizeof(int));
int *col = malloc(n*sizeof(int));
memset(row, 0, sizeof(row));
memset(col, 0, sizeof(col));
[...]
最佳答案
如有疑问,请查看手册页:
$ man memset
MEMSET(3) BSD Library Functions Manual MEMSET(3)
NAME
memset -- fill a byte string with a byte value
LIBRARY
Standard C Library (libc, -lc)
SYNOPSIS
#include <string.h>
^^^^^^^^^^^^^^^^^^^
这告诉您需要 #include <string.h>
为了让编译器看到 memset
的函数原型(prototype).
另请注意,您的代码中存在错误 - 您需要更改:
memset(row, 0, sizeof(row));
memset(col, 0, sizeof(col));
到:
memset(row, 0, m * sizeof(*m));
memset(col, 0, n * sizeof(*n));
关于c - 需要摆脱 memset 警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12965905/