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

时间:2019-10-17 09:56:19

标签: c macos clang stdio macos-catalina

我最近开始在编译C程序时遇到问题,从不同的C包(如 stdio.h stdlib.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但没有结果。

下面的

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

1 个答案:

答案 0 :(得分:1)

为我快速解决问题的方法

gcc -Wno-nullability-completeness file.c