C:warning: null argument where non-null required (argument 2) [-Wnonnull]

main.c:950:32: warning: null argument where non-null required (argument 2) [-Wnonnull]

这个意思说,函数定义里面由一个attribute,标记第二个参数不能为空。

warning.c:25:2: warning: null argument where non-null required (argument 2) [-Wnonnull]

memcmp(&xia, 0, 0);

比如这个memcmp的第一个和第二个参数;

glibc的定义(string.h)如下:

c 复制代码
/* Compare N bytes of S1 and S2.  */
extern int memcmp (const void *__s1, const void *__s2, size_t __n)
     __THROW __attribute_pure__ __nonnull ((1, 2));

为什么要加这个属性?根据源代码看的话,就是在第三个参数不为0的情况下,如果s1和s2有一个是null,那么就会发生SegV。注意是给开发者一个提示,避免问题的发生。

c 复制代码
commit be27d08c05911a658949ba7b84f4321a65a2dbf4 (tag: cvs/fedora-glibc-20040923T0148)
Author: Ulrich Drepper <drepper@redhat.com>
Date:   Wed Sep 22 08:20:57 2004 +0000
    Update.
    2004-09-22  Ulrich Drepper  <drepper@redhat.com>
            * string/string.h: Add __nonnull annotations.
            * stdlib/stdlib.h: Likewise.
相关推荐
RuoZoe9 天前
重塑WPF辉煌?基于DirectX 12的现代.NET UI框架Jalium
c语言
祈安_12 天前
C语言内存函数
c语言·后端
norlan_jame14 天前
C-PHY与D-PHY差异
c语言·开发语言
czy878747514 天前
除了结构体之外,C语言中还有哪些其他方式可以模拟C++的面向对象编程特性
c语言
m0_5312371714 天前
C语言-数组练习进阶
c语言·开发语言·算法
Z9fish14 天前
sse哈工大C语言编程练习23
c语言·数据结构·算法
代码无bug抓狂人14 天前
C语言之单词方阵——深搜(很好的深搜例题)
c语言·开发语言·算法·深度优先
CodeJourney_J14 天前
从“Hello World“ 开始 C++
c语言·c++·学习
枫叶丹414 天前
【Qt开发】Qt界面优化(七)-> Qt样式表(QSS) 样式属性
c语言·开发语言·c++·qt
with-the-flow14 天前
从数学底层的底层原理来讲 random 的函数是怎么实现的
c语言·python·算法