C - 编译程序时出现多个警告"pointer is missing a nullability type specifier",我该怎么办?
C - multiple warnings "pointer is missing a nullability type specifier" when compiling program, what do I do?
我最近开始在编译 C 程序时遇到问题,从 stdio.h 或 [ 等不同的 C 程序包收到 10、20 或 100 条警告=51=]。
警告有些不同,但通常是这样说的:
/usr/local/include/_stdio.h:93:16: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or
_Null_unspecified) [-Wnullability-completeness]
unsigned char *_base;
我的程序仍然可以编译并运行良好,但我担心这需要修复,而且在终端中收到所有这些警告也非常烦人。
我几乎可以肯定这些警告是在我将系统更新到 macOS Catalina 后开始显示的,但我不知道从哪里开始解决它。
更具体地说,当我像这样编译一个简单的helloworld.c程序时
#include <stdio.h>
int main (void) {
printf("Hello World!");
return 0;
}
使用以下命令:
make helloworld
或
gcc helloworld.c -o helloworld
..我收到以下警告,即使程序实际编译。
In file included from helloworld.c:1:
In file included from /usr/local/include/stdio.h:64:
/usr/local/include/_stdio.h:93:16: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
unsigned char *_base;
^
/usr/local/include/_stdio.h:93:16: note: insert '_Nullable' if the pointer may be null
unsigned char *_base;
^
_Nullable
/usr/local/include/_stdio.h:93:16: note: insert '_Nonnull' if the pointer should never be null
unsigned char *_base;
^
_Nonnull
/usr/local/include/_stdio.h:138:32: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
int (* _Nullable _read) (void *, char *, int);
^
/usr/local/include/_stdio.h:138:32: note: insert '_Nullable' if the pointer may be null
int (* _Nullable _read) (void *, char *, int);
^
_Nullable
/usr/local/include/_stdio.h:138:32: note: insert '_Nonnull' if the pointer should never be null
int (* _Nullable _read) (void *, char *, int);
^
_Nonnull
/usr/local/include/_stdio.h:138:40: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
int (* _Nullable _read) (void *, char *, int);
^
/usr/local/include/_stdio.h:138:40: note: insert '_Nullable' if the pointer may be null
int (* _Nullable _read) (void *, char *, int);
^
_Nullable
/usr/local/include/_stdio.h:138:40: note: insert '_Nonnull' if the pointer should never be null
int (* _Nullable _read) (void *, char *, int);
^
_Nonnull
/usr/local/include/_stdio.h:139:35: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
fpos_t (* _Nullable _seek) (void *, fpos_t, int);
^
/usr/local/include/_stdio.h:139:35: note: insert '_Nullable' if the pointer may be null
fpos_t (* _Nullable _seek) (void *, fpos_t, int);
^
_Nullable
/usr/local/include/_stdio.h:139:35: note: insert '_Nonnull' if the pointer should never be null
fpos_t (* _Nullable _seek) (void *, fpos_t, int);
^
_Nonnull
/usr/local/include/_stdio.h:140:32: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
int (* _Nullable _write)(void *, const char *, int);
^
/usr/local/include/_stdio.h:140:32: note: insert '_Nullable' if the pointer may be null
int (* _Nullable _write)(void *, const char *, int);
^
_Nullable
/usr/local/include/_stdio.h:140:32: note: insert '_Nonnull' if the pointer should never be null
int (* _Nullable _write)(void *, const char *, int);
^
_Nonnull
/usr/local/include/_stdio.h:140:46: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
int (* _Nullable _write)(void *, const char *, int);
^
/usr/local/include/_stdio.h:140:46: note: insert '_Nullable' if the pointer may be null
int (* _Nullable _write)(void *, const char *, int);
^
_Nullable
/usr/local/include/_stdio.h:140:46: note: insert '_Nonnull' if the pointer should never be null
int (* _Nullable _write)(void *, const char *, int);
^
_Nonnull
/usr/local/include/_stdio.h:144:18: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
struct __sFILEX *_extra; /* additions to FILE to not break ABI */
^
/usr/local/include/_stdio.h:144:18: note: insert '_Nullable' if the pointer may be null
struct __sFILEX *_extra; /* additions to FILE to not break ABI */
^
_Nullable
/usr/local/include/_stdio.h:144:18: note: insert '_Nonnull' if the pointer should never be null
struct __sFILEX *_extra; /* additions to FILE to not break ABI */
^
_Nonnull
In file included from helloworld.c:1:
/usr/local/include/stdio.h:67:13: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
extern FILE *__stdinp;
^
/usr/local/include/stdio.h:67:13: note: insert '_Nullable' if the pointer may be null
extern FILE *__stdinp;
^
_Nullable
/usr/local/include/stdio.h:67:13: note: insert '_Nonnull' if the pointer should never be null
extern FILE *__stdinp;
^
_Nonnull
/usr/local/include/stdio.h:386:41: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
int (* _Nullable)(void *, const char *, int),
^
/usr/local/include/stdio.h:386:41: note: insert '_Nullable' if the pointer may be null
int (* _Nullable)(void *, const char *, int),
^
_Nullable
/usr/local/include/stdio.h:386:41: note: insert '_Nonnull' if the pointer should never be null
int (* _Nullable)(void *, const char *, int),
^
_Nonnull
/usr/local/include/stdio.h:386:55: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
int (* _Nullable)(void *, const char *, int),
^
/usr/local/include/stdio.h:386:55: note: insert '_Nullable' if the pointer may be null
int (* _Nullable)(void *, const char *, int),
^
_Nullable
/usr/local/include/stdio.h:386:55: note: insert '_Nonnull' if the pointer should never be null
int (* _Nullable)(void *, const char *, int),
^
_Nonnull
/usr/local/include/stdio.h:387:44: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
fpos_t (* _Nullable)(void *, fpos_t, int),
^
/usr/local/include/stdio.h:387:44: note: insert '_Nullable' if the pointer may be null
fpos_t (* _Nullable)(void *, fpos_t, int),
^
_Nullable
/usr/local/include/stdio.h:387:44: note: insert '_Nonnull' if the pointer should never be null
fpos_t (* _Nullable)(void *, fpos_t, int),
^
_Nonnull
/usr/local/include/stdio.h:388:41: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
int (* _Nullable)(void *));
^
/usr/local/include/stdio.h:388:41: note: insert '_Nullable' if the pointer may be null
int (* _Nullable)(void *));
^
_Nullable
/usr/local/include/stdio.h:388:41: note: insert '_Nonnull' if the pointer should never be null
int (* _Nullable)(void *));
^
_Nonnull
/usr/local/include/stdio.h:384:6: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
FILE *funopen(const void *,
^
/usr/local/include/stdio.h:384:6: note: insert '_Nullable' if the pointer may be null
FILE *funopen(const void *,
^
_Nullable
/usr/local/include/stdio.h:384:6: note: insert '_Nonnull' if the pointer should never be null
FILE *funopen(const void *,
^
_Nonnull
13 warnings generated.
编辑:Mike Minaev 提供了我现在正在使用的临时修复程序。命令:
gcc -Wno-nullability-completeness helloworld.c -o helloworld
编辑:我环顾四周并尝试了 or 的各种解决方案,包括使用 CLI 重新安装 xcode 但没有结果。
下面的 Jonathan Leffler 推测这可能是因为我的头文件位于 usr/local/include
而不是 usr/include
但没有建议修复。
我的临时快速修复:
gcc -Wno-nullability-completeness file.c
我最近开始在编译 C 程序时遇到问题,从 stdio.h 或 [ 等不同的 C 程序包收到 10、20 或 100 条警告=51=]。
警告有些不同,但通常是这样说的:
/usr/local/include/_stdio.h:93:16: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or
_Null_unspecified) [-Wnullability-completeness]
unsigned char *_base;
我的程序仍然可以编译并运行良好,但我担心这需要修复,而且在终端中收到所有这些警告也非常烦人。
我几乎可以肯定这些警告是在我将系统更新到 macOS Catalina 后开始显示的,但我不知道从哪里开始解决它。
更具体地说,当我像这样编译一个简单的helloworld.c程序时
#include <stdio.h>
int main (void) {
printf("Hello World!");
return 0;
}
使用以下命令:
make helloworld
或
gcc helloworld.c -o helloworld
..我收到以下警告,即使程序实际编译。
In file included from helloworld.c:1:
In file included from /usr/local/include/stdio.h:64:
/usr/local/include/_stdio.h:93:16: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
unsigned char *_base;
^
/usr/local/include/_stdio.h:93:16: note: insert '_Nullable' if the pointer may be null
unsigned char *_base;
^
_Nullable
/usr/local/include/_stdio.h:93:16: note: insert '_Nonnull' if the pointer should never be null
unsigned char *_base;
^
_Nonnull
/usr/local/include/_stdio.h:138:32: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
int (* _Nullable _read) (void *, char *, int);
^
/usr/local/include/_stdio.h:138:32: note: insert '_Nullable' if the pointer may be null
int (* _Nullable _read) (void *, char *, int);
^
_Nullable
/usr/local/include/_stdio.h:138:32: note: insert '_Nonnull' if the pointer should never be null
int (* _Nullable _read) (void *, char *, int);
^
_Nonnull
/usr/local/include/_stdio.h:138:40: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
int (* _Nullable _read) (void *, char *, int);
^
/usr/local/include/_stdio.h:138:40: note: insert '_Nullable' if the pointer may be null
int (* _Nullable _read) (void *, char *, int);
^
_Nullable
/usr/local/include/_stdio.h:138:40: note: insert '_Nonnull' if the pointer should never be null
int (* _Nullable _read) (void *, char *, int);
^
_Nonnull
/usr/local/include/_stdio.h:139:35: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
fpos_t (* _Nullable _seek) (void *, fpos_t, int);
^
/usr/local/include/_stdio.h:139:35: note: insert '_Nullable' if the pointer may be null
fpos_t (* _Nullable _seek) (void *, fpos_t, int);
^
_Nullable
/usr/local/include/_stdio.h:139:35: note: insert '_Nonnull' if the pointer should never be null
fpos_t (* _Nullable _seek) (void *, fpos_t, int);
^
_Nonnull
/usr/local/include/_stdio.h:140:32: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
int (* _Nullable _write)(void *, const char *, int);
^
/usr/local/include/_stdio.h:140:32: note: insert '_Nullable' if the pointer may be null
int (* _Nullable _write)(void *, const char *, int);
^
_Nullable
/usr/local/include/_stdio.h:140:32: note: insert '_Nonnull' if the pointer should never be null
int (* _Nullable _write)(void *, const char *, int);
^
_Nonnull
/usr/local/include/_stdio.h:140:46: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
int (* _Nullable _write)(void *, const char *, int);
^
/usr/local/include/_stdio.h:140:46: note: insert '_Nullable' if the pointer may be null
int (* _Nullable _write)(void *, const char *, int);
^
_Nullable
/usr/local/include/_stdio.h:140:46: note: insert '_Nonnull' if the pointer should never be null
int (* _Nullable _write)(void *, const char *, int);
^
_Nonnull
/usr/local/include/_stdio.h:144:18: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
struct __sFILEX *_extra; /* additions to FILE to not break ABI */
^
/usr/local/include/_stdio.h:144:18: note: insert '_Nullable' if the pointer may be null
struct __sFILEX *_extra; /* additions to FILE to not break ABI */
^
_Nullable
/usr/local/include/_stdio.h:144:18: note: insert '_Nonnull' if the pointer should never be null
struct __sFILEX *_extra; /* additions to FILE to not break ABI */
^
_Nonnull
In file included from helloworld.c:1:
/usr/local/include/stdio.h:67:13: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
extern FILE *__stdinp;
^
/usr/local/include/stdio.h:67:13: note: insert '_Nullable' if the pointer may be null
extern FILE *__stdinp;
^
_Nullable
/usr/local/include/stdio.h:67:13: note: insert '_Nonnull' if the pointer should never be null
extern FILE *__stdinp;
^
_Nonnull
/usr/local/include/stdio.h:386:41: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
int (* _Nullable)(void *, const char *, int),
^
/usr/local/include/stdio.h:386:41: note: insert '_Nullable' if the pointer may be null
int (* _Nullable)(void *, const char *, int),
^
_Nullable
/usr/local/include/stdio.h:386:41: note: insert '_Nonnull' if the pointer should never be null
int (* _Nullable)(void *, const char *, int),
^
_Nonnull
/usr/local/include/stdio.h:386:55: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
int (* _Nullable)(void *, const char *, int),
^
/usr/local/include/stdio.h:386:55: note: insert '_Nullable' if the pointer may be null
int (* _Nullable)(void *, const char *, int),
^
_Nullable
/usr/local/include/stdio.h:386:55: note: insert '_Nonnull' if the pointer should never be null
int (* _Nullable)(void *, const char *, int),
^
_Nonnull
/usr/local/include/stdio.h:387:44: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
fpos_t (* _Nullable)(void *, fpos_t, int),
^
/usr/local/include/stdio.h:387:44: note: insert '_Nullable' if the pointer may be null
fpos_t (* _Nullable)(void *, fpos_t, int),
^
_Nullable
/usr/local/include/stdio.h:387:44: note: insert '_Nonnull' if the pointer should never be null
fpos_t (* _Nullable)(void *, fpos_t, int),
^
_Nonnull
/usr/local/include/stdio.h:388:41: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
int (* _Nullable)(void *));
^
/usr/local/include/stdio.h:388:41: note: insert '_Nullable' if the pointer may be null
int (* _Nullable)(void *));
^
_Nullable
/usr/local/include/stdio.h:388:41: note: insert '_Nonnull' if the pointer should never be null
int (* _Nullable)(void *));
^
_Nonnull
/usr/local/include/stdio.h:384:6: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
FILE *funopen(const void *,
^
/usr/local/include/stdio.h:384:6: note: insert '_Nullable' if the pointer may be null
FILE *funopen(const void *,
^
_Nullable
/usr/local/include/stdio.h:384:6: note: insert '_Nonnull' if the pointer should never be null
FILE *funopen(const void *,
^
_Nonnull
13 warnings generated.
编辑:Mike Minaev 提供了我现在正在使用的临时修复程序。命令:
gcc -Wno-nullability-completeness helloworld.c -o helloworld
编辑:我环顾四周并尝试了
Jonathan Leffler 推测这可能是因为我的头文件位于 usr/local/include
而不是 usr/include
但没有建议修复。
我的临时快速修复:
gcc -Wno-nullability-completeness file.c