加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

C memset警告

发布时间:2020-12-16 10:45:18 所属栏目:百科 来源:网络整理
导读:这是我的警告. warning: passing argument 2 of ‘memset’ makes integer from pointer without a cast 然后我改变如下(使NULL为0) Before Change : memset(key,NULL,KEY_BYTES);After Change : memset(key,KEY_BYTES); 警告已删除. 我正在使用linux gcc编
这是我的警告.

warning: passing argument 2 of ‘memset’ makes integer from pointer without a cast

然后我改变如下(使NULL为0)

Before Change : memset(key,NULL,KEY_BYTES);
After Change : memset(key,KEY_BYTES);

警告已删除.

我正在使用linux& gcc编译器,C.

这是正确的行动吗?

解决方法

根据实现,C标准库有时将NULL定义为零整数(这将避免您看到的警告),但有时将NULL定义为零转换为void指针.后一种实现会导致您看到的警告.

要回答您的具体问题,在这种情况下您不应该使用NULL.无论实现如何,NULL都旨在用作空指针,而不是整数零的同义词.如果要使用memset用零填充内存块,则将零作为第二个参数传递,而不是NULL.

引自http://en.wikipedia.org/wiki/Stdlib.h:

NULL

The stdlib.h and stddef.h header files define
the macro NULL,which yields a null pointer
constant,and represents a pointer value that
is guaranteed not to point to a valid
address in memory.

Variants

NULL may be defined as a
constant expression equal to int zero,
long int zero,or zero cast to a void
* pointer:

#define NULL 0
#define NULL 0L
#define NULL ((void *) 0)

Although the null pointer constant is always represented in C by the symbolic constant 0 or by 0 cast to a void pointer,the actual bit representation of such a pointer is system-specific and may contain one-bits.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读