【问题标题】:Need to get rid of the memset warning需要摆脱 memset 警告
【发布时间】:2012-10-19 00:51:58
【问题描述】:

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

警告:内置函数 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));
    [...]

【问题讨论】:

标签: c warnings memset


【解决方案1】:

如有疑问,请查看手册页:

$ 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 &lt;string.h&gt; 才能让编译器看到memset 的函数原型。

另请注意,您的代码中存在错误 - 您需要更改:

memset(row, 0, sizeof(row));
memset(col, 0, sizeof(col));

到:

memset(row, 0, m * sizeof(*m));
memset(col, 0, n * sizeof(*n));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-01-15
    • 1970-01-01
    • 2016-11-20
    • 1970-01-01
    • 1970-01-01
    • 2015-11-16
    • 2017-01-25
    相关资源
    最近更新 更多