c/c++语言开发共享C:关于结构可见性的警告

我有一个复杂的C项目。 在文件message.h我声明了这个结构

 struct message { int err; struct header { char *protocol_version; char *type; long int sequence_number; } header; struct body { int num_tag; char *tag_labels[LEN]; int num_attr_tag[LEN]; char *attr_labels[LEN][LEN]; char *attr_values[LEN][LEN]; char *attr_types[LEN][LEN]; } body; }; 

在文件“castfunctions.h”中,我包含文件“message.h”,我声明函数“setClientNat”

 #include  void *setClientNat(struct message *msg); 

当我编译时,我有这个警告

 castfunctions.h:warning: declaration of 'struct message' will not be visible outside of this function [-Wvisibility] void *setClientNat(struct message *msg); 

谁能帮我?

    在此函数之外不会显示’struct message’的声明[-Wvisibility]

    该警告意味着此时未声明struct message ,因此它用作无用的前向声明。

    这意味着您显示的代码并不完全正确,您的文件中包含的内容与您显示的内容相同 – 错误在代码中未显示给我们。

    以下是您可能收到警告的原因。

     #ifndef MESSAGE_H #define MESSAGE_H struct message { .... }; #endif` 

    然后在源文件中使用头文件,如下所示:

      #include  #include  

    事实上, 文件也定义了一个
    MESSAGE_H宏,渲染整个message.h不可见。 或者, thisnthat.h头部有一个#define message something_else

    除了nos’的答案,你应该使用-E选项而不是-c运行gcc。 这将输出预处理的翻译单元,因此您可以看到编译器真正看到的内容。 输出还提到了包含的每个文件。

      以上就是c/c++开发分享C:关于结构可见性的警告相关内容,想了解更多C/C++开发(异常处理)及C/C++游戏开发关注计算机技术网(www.ctvol.com)!)。

      本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

      ctvol管理联系方式QQ:251552304

      本文章地址:https://www.ctvol.com/c-cdevelopment/519078.html

      (0)
      上一篇 2020年12月5日
      下一篇 2020年12月5日

      精彩推荐