gpt4 book ai didi

c - 需要摆脱 memset 警告

转载 作者:太空宇宙 更新时间:2023-11-04 00:40:00 25 4
gpt4 key购买 nike

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

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com