在下面的声明中_Nullable是什么意思?

void foo(int *_Nullable ptr)

版本11.4的GCC没有编译该代码,因为它将_Nullable关键字视为参数名.然而,我在MAN 7页上看到了这个关键词: https://man7.org/linux/man-pages/man2/epoll_ctl.2.htmlhttps://man7.org/linux/man-pages/man2/timer_gettime.2.html

Godbolt

推荐答案

_Nullable simply means that the pointer passed to the function is allowed to be NULL. It is however not a keyword in C (and doesn't occur even once in the draft for the C23 standard) but an extension supported only by some compilers, for example and .

Linux man页使用_Nullable来向读者指示它们被允许传递NULL指针,但头文件中的实际声明不是_Nullable.


希望向编译器提供静态分析和优化提示_Nullable_Nonnull(指示指针not可以是NULL)的库将视所使用的平台/编译器而 Select 性地将指针声明为_Nullable_Nonnull.

示例:在Linux上的zipconf.h(针对libzip的特定于平台的包含文件)中,您将看到

#define _Nullable
#define _Nonnull

and all the zip functions will have both _Nullable and _Nonnull in their declarations. On Linux these will however be replaced with nothing thanks to the above #defines. On a platform dominated by or these definitions will not exist and the implementation specific keywords will then be passed on to the compiler as-is.

C++相关问答推荐

使用sd-设备列举设备导致seg错误

数组元素的编号索引

malloc实现:判断正确的分配对齐

VS代码C/C++扩展intellisense无法检测环境特定函数'

在函数中使用复合文字来初始化C语言中的变量

如何调试LD_PRELOAD库中的构造函数?

如何知道我是否从非阻塞套接字读取所有内容

非常大的数组的大小

函数的限制限定指针参数允许优化调用方函数吗?

在每种If-Else情况下执行语句的最佳方式

防止规范模式在C++中 echo 特殊字符

有什么方法可以将字符串与我们 Select 的子字符串分开吗?喜欢:SIN(LOG(10))

如何在C中使数组变量的值为常量?

不同出处的指针可以相等吗?

不确定如何处理此编译错误

从Raku nativecall调用时精度不同

使用 strtok 多次分割一个字符串会导致意外行为

C 程序不显示任何输出,但它接受 CS50 Lab1 的输入问题

为什么实现文件中的自由函数默认没有内部链接?

使用 SDL2 的 C 程序中的内存泄漏