C-编译程序时出现多次警告“指针缺少可空性类型说明符”,我该怎么办?

问题描述 投票:4回答:1

我最近开始在编译C程序时遇到问题,从不同的C包(如stdio.hstdlib.h)获得10、20或100条警告。

警告有些不同,但通常会这样说:

/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 

编辑:我环顾四周并尝试了this threadthis thread的各种解决方案,包括使用CLI重新安装xcode,甚至尝试将以下代码添加到stdio.h(但现在将其删除):

NS_ASSUME_NONNULL_BEGIN 

NS_ASSUME_NONNULL_END

..但没有结果。

Jonathan Leffler下面推测这可能是因为我的头文件位于usr/local/include中而不是usr/include中,但未建议修复。

c macos clang stdio macos-catalina
1个回答
1
投票

为我快速修复:

gcc -Wno-nullability-completeness file.c
© www.soinside.com 2019 - 2024. All rights reserved.