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.
相关推荐
小莞尔3 天前
【51单片机】【protues仿真】基于51单片机的篮球计时计分器系统
c语言·stm32·单片机·嵌入式硬件·51单片机
小莞尔3 天前
【51单片机】【protues仿真】 基于51单片机八路抢答器系统
c语言·开发语言·单片机·嵌入式硬件·51单片机
liujing102329293 天前
Day03_刷题niuke20250915
c语言
第七序章3 天前
【C++STL】list的详细用法和底层实现
c语言·c++·自然语言处理·list
l1t3 天前
利用DeepSeek实现服务器客户端模式的DuckDB原型
服务器·c语言·数据库·人工智能·postgresql·协议·duckdb
l1t3 天前
利用美团龙猫用libxml2编写XML转CSV文件C程序
xml·c语言·libxml2·解析器
Gu_shiwww3 天前
数据结构8——双向链表
c语言·数据结构·python·链表·小白初步
你怎么知道我是队长3 天前
C语言---循环结构
c语言·开发语言·算法
程序猿编码3 天前
基于 Linux 内核模块的字符设备 FIFO 驱动设计与实现解析(C/C++代码实现)
linux·c语言·c++·内核模块·fifo·字符设备
mark-puls3 天前
C语言打印爱心
c语言·开发语言·算法