c - 需要摆脱 memset 警告

标签 c warnings memset

如果我编译下面的代码,我会收到这样的警告:

警告:内置函数 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/

相关文章:

c - 如何在Linux中正确接收串行通信的十六进制数据

c - 如何使用本地字母顺序编号而不是 ascii

objective-c - 子类中 BOOL 上的 "Subscripted value is neither array nor pointer"错误

c - 在c中的数字序列中找到平均值,同时忽略序列中的负数

ios - 忽略 Xcode 6 中的警告

python - 带有 scrapy 的警告 "_mysql was already imported"

c++ - memset() 在 C++ 中的工作原理

c++ - 如何将 "warnings as error"规则添加到 Qt .pro 文件?

C 中 memset 函数的复杂性

c - 正确清除数组